@alwith/module-chat 0.1.17 → 0.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/approval/choice-elicitation-form.js +1 -1
  2. package/dist/approval/choice-schema.d.ts +1 -1
  3. package/dist/approval/choice-schema.js +1 -1
  4. package/dist/approval/permission-view.js +1 -1
  5. package/dist/approval/schema-elicitation-form.d.ts +1 -1
  6. package/dist/approval/schema-elicitation-form.js +1 -1
  7. package/dist/codex/activity-group.js +6 -6
  8. package/dist/codex/assistant-message.js +2 -2
  9. package/dist/codex/markdown-renderer.d.ts +1 -0
  10. package/dist/codex/markdown-renderer.js +5 -5
  11. package/dist/codex/navigation-rail.d.ts +10 -2
  12. package/dist/codex/navigation-rail.js +1 -1
  13. package/dist/codex/styles.css +32 -0
  14. package/dist/codex/thread-virtualizer.d.ts +3 -1
  15. package/dist/codex/thread-virtualizer.js +1 -1
  16. package/dist/codex/virtualized-turn-list.d.ts +6 -0
  17. package/dist/codex/virtualized-turn-list.js +1 -1
  18. package/dist/composer/completion-menu.js +2 -2
  19. package/dist/composer/completion-trigger.js +1 -1
  20. package/dist/composer/menu-radio.js +1 -1
  21. package/dist/composer/model-select.d.ts +2 -2
  22. package/dist/composer/model-select.js +1 -1
  23. package/dist/composer/prompt-input-attachments.js +1 -1
  24. package/dist/composer/prompt-input-clipboard.d.ts +0 -1
  25. package/dist/composer/prompt-input-clipboard.js +1 -1
  26. package/dist/composer/prompt-input-textarea.js +2 -2
  27. package/dist/composer/prompt-input.js +1 -1
  28. package/dist/image-preview-dialog.js +1 -1
  29. package/dist/lib/markdown-parser.d.ts +1 -0
  30. package/dist/lib/markdown-parser.js +1 -1
  31. package/dist/lib/streaming-markdown.js +1 -1
  32. package/dist/search/chat-search.js +1 -1
  33. package/dist/search/find-bar.js +1 -1
  34. package/dist/types.d.ts +2 -2
  35. package/dist/ui/badge.js +1 -1
  36. package/dist/ui/button.js +1 -1
  37. package/dist/ui/dialog.d.ts +1 -1
  38. package/dist/ui/dialog.js +1 -1
  39. package/dist/ui/dropdown-menu.d.ts +1 -1
  40. package/dist/ui/dropdown-menu.js +1 -1
  41. package/dist/ui/field.js +1 -1
  42. package/dist/ui/input-group.d.ts +2 -2
  43. package/dist/ui/input-group.js +1 -1
  44. package/package.json +6 -4
@@ -1 +1 @@
1
- import{jsx as s,jsxs as l}from"react/jsx-runtime";import{autoUpdate as D}from"@floating-ui/dom";import{useCallback as k,useEffect as A,useLayoutEffect as z,useMemo as B,useRef as K,useState as U}from"react";import{createPortal as X}from"react-dom";import{Badge as J}from"../ui/badge.js";import{Button as L}from"../ui/button.js";import{Checkbox as O}from"../ui/checkbox.js";import{Input as q}from"../ui/input.js";import{Label as H}from"../ui/label.js";import{RadioGroup as Y,RadioGroupItem as M}from"../ui/radio-group.js";import{Textarea as Z}from"../ui/textarea.js";import{cn as G}from"cn";import{elicitationFields as ee,elicitationLabels as R,elicitationOptions as I,isMultiSelect as S}from"./choice-schema.js";var d="__other__";function he({current:o,total:P,anchorRef:g,t:u,onAccept:F,onDecline:Q}){let x=B(()=>o?ee(o.requestedSchema):[],[o]),[w,p]=U({}),T=K(null);A(()=>{if(o?.elicitationId===void 0)return;let e={};for(let{key:n,property:r}of x)if(!S(r)){let c=I(r)[0];if(c)e[n]={selected:c.value}}p(e)},[o?.elicitationId,x]),A(()=>{if(o?.elicitationId!==void 0&&T.current&&document.activeElement?.tagName!=="INPUT"&&document.activeElement?.tagName!=="TEXTAREA")T.current.focus()},[o?.elicitationId]);let[b,_]=U(null),[C,V]=U(null),N=k(()=>{let e=g.current;if(!e)return;let n=e.getBoundingClientRect();if(n.width===0){let r=Math.min(640,window.innerWidth*0.9);_({left:(window.innerWidth-r)/2,width:r,bottom:24});return}_({left:n.left,width:n.width,bottom:window.innerHeight-n.bottom+20})},[g]);z(()=>{if(!o)return;let e=0,n=()=>{if(g.current){N();return}e=requestAnimationFrame(n)};return n(),()=>cancelAnimationFrame(e)},[o,N,g]),z(()=>{let e=g.current;if(!o||!e||!C)return;return D(e,C,N,{animationFrame:!0})},[o,C,g,N]);let y=B(()=>{if(!o)return!1;for(let{key:e,property:n}of x){let r=w[e];if(!r)return!1;if(S(n)){if(!r.selectedSet||r.selectedSet.size===0)return!1;if(r.selectedSet.has(d)&&!r.otherText?.trim())return!1}else{if(!r.selected)return!1;if(r.selected===d&&!r.otherText?.trim())return!1}}return!0},[o,x,w]),W=k(async()=>{if(!o)return;if(!y)return;let e={},n={};for(let{key:r,property:c}of x){let a=w[r];if(!a)continue;let f;if(S(c))e[r]=Array.from(a.selectedSet??[]).map((m)=>m===d?(a.otherText??"").trim():m).filter(Boolean);else{let m=a.selected??"";if(e[r]=m===d?(a.otherText??"").trim():m,m!==d)f=I(c).find((t)=>t.value===m)?.preview}let h=a.notes?.trim();if(f||h)n[r]={...f&&{preview:f},...h&&{notes:h}}}await F(o.elicitationId,e,n)},[o,x,w,y,F]),j=k(async()=>{if(o)await Q(o.elicitationId)},[o,Q]);if(!o||!b)return null;return X(l("div",{"data-overlay":"ask-user-question",tabIndex:0,onKeyDown:(e)=>{if(e.key==="Escape")e.preventDefault(),j()},className:"bg-card border-border fixed z-50 flex flex-col overflow-hidden rounded-lg border shadow-lg outline-none",style:{left:b.left,width:b.width,bottom:b.bottom,maxHeight:"70vh"},ref:(e)=>{T.current=e,V(e)},children:[l("div",{className:"border-border flex shrink-0 items-center justify-between gap-2 border-b px-3 py-2",children:[s("div",{className:"text-foreground text-sm font-medium",children:u("askUserQuestion.title")}),P>1&&s("span",{className:"text-muted-foreground shrink-0 text-xs",children:`1 / ${P}`})]}),s("div",{className:"min-h-0 flex-1 overflow-y-auto",children:s("div",{className:"space-y-4 px-3 py-3",children:x.map(({key:e,property:n},r)=>{let c=w[e],a=c?.selected,f=c?.selectedSet??new Set,h=I(n),m=S(n);return l("div",{className:"space-y-2",children:[l("div",{className:"flex items-center gap-2",children:[s(J,{variant:"secondary",className:"font-mono text-[10px] tracking-wide uppercase",children:R(n).title??e}),s("div",{className:"text-foreground text-sm font-medium",children:R(n).description})]}),m?l("div",{className:"space-y-1.5 ps-1",children:[h.map((t)=>l("label",{className:"hover:bg-muted/40 flex cursor-pointer items-center gap-2 rounded-sm px-1.5 py-1",children:[s(O,{checked:f.has(t.value),onCheckedChange:(i)=>{p((v)=>{let E=new Set(v[e]?.selectedSet??new Set);if(i)E.add(t.value);else E.delete(t.value);return{...v,[e]:{...v[e],selectedSet:E}}})}}),l("div",{className:"min-w-0 flex-1",children:[s("div",{className:"text-foreground text-sm",children:t.label}),t.description&&s("div",{className:"text-muted-foreground text-xs",children:t.description})]})]},t.value)),l("label",{className:"hover:bg-muted/40 flex cursor-pointer items-center gap-2 rounded-sm px-1.5 py-1",children:[s(O,{checked:f.has(d),onCheckedChange:(t)=>{p((i)=>{let v=new Set(i[e]?.selectedSet??new Set);if(t)v.add(d);else v.delete(d);return{...i,[e]:{...i[e],selectedSet:v}}})}}),s("div",{className:"text-foreground min-w-0 flex-1 text-sm",children:u("askUserQuestion.other")})]}),f.has(d)&&s("div",{className:"ps-7",children:s(q,{placeholder:u("askUserQuestion.otherPlaceholder"),value:c?.otherText??"",onChange:(t)=>p((i)=>({...i,[e]:{...i[e],otherText:t.target.value}}))})})]}):l(Y,{value:a??"",onValueChange:(t)=>p((i)=>({...i,[e]:{...i[e],selected:t}})),className:"space-y-1.5 ps-1",children:[h.map((t)=>{let i=`${r}:${t.value}`;return l("div",{className:G("hover:bg-muted/40 flex cursor-pointer items-center gap-2 rounded-sm px-1.5 py-1",a===t.value&&"bg-muted/60"),children:[s(M,{value:t.value,id:i}),l(H,{htmlFor:i,className:"min-w-0 flex-1 cursor-pointer",children:[s("div",{className:"text-foreground text-sm font-normal",children:t.label}),t.description&&s("div",{className:"text-muted-foreground text-xs font-normal",children:t.description})]})]},t.value)}),l("div",{className:G("hover:bg-muted/40 flex items-center gap-2 rounded-sm px-1.5 py-1",a===d&&"bg-muted/60"),children:[s(M,{value:d,id:`${r}:other`,className:"mt-0.5"}),s(H,{htmlFor:`${r}:other`,className:"text-foreground min-w-0 flex-1 cursor-pointer text-sm font-normal",children:u("askUserQuestion.other")})]}),a===d&&s("div",{className:"ps-7",children:s(q,{placeholder:u("askUserQuestion.otherPlaceholder"),value:c?.otherText??"",onChange:(t)=>p((i)=>({...i,[e]:{...i[e],otherText:t.target.value}}))})})]}),!m&&a&&a!==d&&(()=>{let t=h.find((i)=>i.value===a)?.preview;if(!t)return null;return s("pre",{className:"bg-muted/50 text-muted-foreground ms-1 mt-1 overflow-auto rounded-sm px-2 py-1.5 font-mono text-[11px] whitespace-pre-wrap",children:t})})(),h.some((t)=>t.preview)&&s(Z,{placeholder:u("askUserQuestion.notesPlaceholder"),value:c?.notes??"",onChange:(t)=>p((i)=>({...i,[e]:{...i[e],notes:t.target.value}})),rows:1,className:"min-h-0 resize-none text-xs"})]},e)})})}),l("div",{className:"border-border bg-card flex shrink-0 items-center justify-end gap-2 border-t px-3 py-2",children:[s(L,{variant:"ghost",size:"sm",onClick:()=>void j(),children:u("askUserQuestion.cancel")}),s(L,{size:"sm",disabled:!y,onClick:()=>void W(),children:u("askUserQuestion.submit")})]})]}),document.body)}export{he as ChoiceElicitationForm};
1
+ import{jsx as s,jsxs as l}from"react/jsx-runtime";import{autoUpdate as D}from"@floating-ui/dom";import{cn as A}from"cn";import{useCallback as k,useEffect as z,useLayoutEffect as B,useMemo as L,useRef as K,useState as U}from"react";import{createPortal as X}from"react-dom";import{Badge as J}from"../ui/badge.js";import{Button as O}from"../ui/button.js";import{Checkbox as q}from"../ui/checkbox.js";import{Input as H}from"../ui/input.js";import{Label as M}from"../ui/label.js";import{RadioGroup as Y,RadioGroupItem as G}from"../ui/radio-group.js";import{Textarea as Z}from"../ui/textarea.js";import{elicitationFields as ee,elicitationLabels as R,elicitationOptions as I,isMultiSelect as S}from"./choice-schema.js";var d="__other__";function he({current:o,total:P,anchorRef:g,t:u,onAccept:F,onDecline:Q}){let x=L(()=>o?ee(o.requestedSchema):[],[o]),[w,p]=U({}),T=K(null);z(()=>{if(o?.elicitationId===void 0)return;let e={};for(let{key:n,property:r}of x)if(!S(r)){let c=I(r)[0];if(c)e[n]={selected:c.value}}p(e)},[o?.elicitationId,x]),z(()=>{if(o?.elicitationId!==void 0&&T.current&&document.activeElement?.tagName!=="INPUT"&&document.activeElement?.tagName!=="TEXTAREA")T.current.focus()},[o?.elicitationId]);let[b,_]=U(null),[C,V]=U(null),N=k(()=>{let e=g.current;if(!e)return;let n=e.getBoundingClientRect();if(n.width===0){let r=Math.min(640,window.innerWidth*0.9);_({left:(window.innerWidth-r)/2,width:r,bottom:24});return}_({left:n.left,width:n.width,bottom:window.innerHeight-n.bottom+20})},[g]);B(()=>{if(!o)return;let e=0,n=()=>{if(g.current){N();return}e=requestAnimationFrame(n)};return n(),()=>cancelAnimationFrame(e)},[o,N,g]),B(()=>{let e=g.current;if(!o||!e||!C)return;return D(e,C,N,{animationFrame:!0})},[o,C,g,N]);let y=L(()=>{if(!o)return!1;for(let{key:e,property:n}of x){let r=w[e];if(!r)return!1;if(S(n)){if(!r.selectedSet||r.selectedSet.size===0)return!1;if(r.selectedSet.has(d)&&!r.otherText?.trim())return!1}else{if(!r.selected)return!1;if(r.selected===d&&!r.otherText?.trim())return!1}}return!0},[o,x,w]),W=k(async()=>{if(!o)return;if(!y)return;let e={},n={};for(let{key:r,property:c}of x){let a=w[r];if(!a)continue;let f;if(S(c))e[r]=Array.from(a.selectedSet??[]).map((m)=>m===d?(a.otherText??"").trim():m).filter(Boolean);else{let m=a.selected??"";if(e[r]=m===d?(a.otherText??"").trim():m,m!==d)f=I(c).find((t)=>t.value===m)?.preview}let h=a.notes?.trim();if(f||h)n[r]={...f&&{preview:f},...h&&{notes:h}}}await F(o.elicitationId,e,n)},[o,x,w,y,F]),j=k(async()=>{if(o)await Q(o.elicitationId)},[o,Q]);if(!o||!b)return null;return X(l("div",{"data-overlay":"ask-user-question",tabIndex:0,onKeyDown:(e)=>{if(e.key==="Escape")e.preventDefault(),j()},className:"bg-card border-border fixed z-50 flex flex-col overflow-hidden rounded-lg border shadow-lg outline-none",style:{left:b.left,width:b.width,bottom:b.bottom,maxHeight:"70vh"},ref:(e)=>{T.current=e,V(e)},children:[l("div",{className:"border-border flex shrink-0 items-center justify-between gap-2 border-b px-3 py-2",children:[s("div",{className:"text-foreground text-sm font-medium",children:u("askUserQuestion.title")}),P>1&&s("span",{className:"text-muted-foreground shrink-0 text-xs",children:`1 / ${P}`})]}),s("div",{className:"min-h-0 flex-1 overflow-y-auto",children:s("div",{className:"space-y-4 px-3 py-3",children:x.map(({key:e,property:n},r)=>{let c=w[e],a=c?.selected,f=c?.selectedSet??new Set,h=I(n),m=S(n);return l("div",{className:"space-y-2",children:[l("div",{className:"flex items-center gap-2",children:[s(J,{variant:"secondary",className:"font-mono text-[10px] tracking-wide uppercase",children:R(n).title??e}),s("div",{className:"text-foreground text-sm font-medium",children:R(n).description})]}),m?l("div",{className:"space-y-1.5 ps-1",children:[h.map((t)=>l("label",{className:"hover:bg-muted/40 flex cursor-pointer items-center gap-2 rounded-sm px-1.5 py-1",children:[s(q,{checked:f.has(t.value),onCheckedChange:(i)=>{p((v)=>{let E=new Set(v[e]?.selectedSet??new Set);if(i)E.add(t.value);else E.delete(t.value);return{...v,[e]:{...v[e],selectedSet:E}}})}}),l("div",{className:"min-w-0 flex-1",children:[s("div",{className:"text-foreground text-sm",children:t.label}),t.description&&s("div",{className:"text-muted-foreground text-xs",children:t.description})]})]},t.value)),l("label",{className:"hover:bg-muted/40 flex cursor-pointer items-center gap-2 rounded-sm px-1.5 py-1",children:[s(q,{checked:f.has(d),onCheckedChange:(t)=>{p((i)=>{let v=new Set(i[e]?.selectedSet??new Set);if(t)v.add(d);else v.delete(d);return{...i,[e]:{...i[e],selectedSet:v}}})}}),s("div",{className:"text-foreground min-w-0 flex-1 text-sm",children:u("askUserQuestion.other")})]}),f.has(d)&&s("div",{className:"ps-7",children:s(H,{placeholder:u("askUserQuestion.otherPlaceholder"),value:c?.otherText??"",onChange:(t)=>p((i)=>({...i,[e]:{...i[e],otherText:t.target.value}}))})})]}):l(Y,{value:a??"",onValueChange:(t)=>p((i)=>({...i,[e]:{...i[e],selected:t}})),className:"space-y-1.5 ps-1",children:[h.map((t)=>{let i=`${r}:${t.value}`;return l("div",{className:A("hover:bg-muted/40 flex cursor-pointer items-center gap-2 rounded-sm px-1.5 py-1",a===t.value&&"bg-muted/60"),children:[s(G,{value:t.value,id:i}),l(M,{htmlFor:i,className:"min-w-0 flex-1 cursor-pointer",children:[s("div",{className:"text-foreground text-sm font-normal",children:t.label}),t.description&&s("div",{className:"text-muted-foreground text-xs font-normal",children:t.description})]})]},t.value)}),l("div",{className:A("hover:bg-muted/40 flex items-center gap-2 rounded-sm px-1.5 py-1",a===d&&"bg-muted/60"),children:[s(G,{value:d,id:`${r}:other`,className:"mt-0.5"}),s(M,{htmlFor:`${r}:other`,className:"text-foreground min-w-0 flex-1 cursor-pointer text-sm font-normal",children:u("askUserQuestion.other")})]}),a===d&&s("div",{className:"ps-7",children:s(H,{placeholder:u("askUserQuestion.otherPlaceholder"),value:c?.otherText??"",onChange:(t)=>p((i)=>({...i,[e]:{...i[e],otherText:t.target.value}}))})})]}),!m&&a&&a!==d&&(()=>{let t=h.find((i)=>i.value===a)?.preview;if(!t)return null;return s("pre",{className:"bg-muted/50 text-muted-foreground ms-1 mt-1 overflow-auto rounded-sm px-2 py-1.5 font-mono text-[11px] whitespace-pre-wrap",children:t})})(),h.some((t)=>t.preview)&&s(Z,{placeholder:u("askUserQuestion.notesPlaceholder"),value:c?.notes??"",onChange:(t)=>p((i)=>({...i,[e]:{...i[e],notes:t.target.value}})),rows:1,className:"min-h-0 resize-none text-xs"})]},e)})})}),l("div",{className:"border-border bg-card flex shrink-0 items-center justify-end gap-2 border-t px-3 py-2",children:[s(O,{variant:"ghost",size:"sm",onClick:()=>void j(),children:u("askUserQuestion.cancel")}),s(O,{size:"sm",disabled:!y,onClick:()=>void W(),children:u("askUserQuestion.submit")})]})]}),document.body)}export{he as ChoiceElicitationForm};
@@ -1,4 +1,4 @@
1
- import type { ElicitationPropertySchema, ElicitationSchema } from "@agentclientprotocol/sdk/experimental/v2";
1
+ import type { ElicitationPropertySchema, ElicitationSchema } from "@agentclientprotocol/sdk/experimental/v2/unstable";
2
2
  export interface ElicitationField {
3
3
  key: string;
4
4
  property: ElicitationPropertySchema;
@@ -1 +1 @@
1
- function c(t){return Object.entries(t.properties??{}).map(([n,i])=>({key:n,property:i}))}function p(t){let{title:n,description:i}=t;return{title:n??void 0,description:i??void 0}}function o(t){return t.type==="array"}function s(t){return(o(t)?t.items?.oneOf??[]:t.oneOf??[]).map((i)=>{let e=i,r=e.const??e.title??"";return{value:r,label:e.title??r,...e.description?{description:e.description}:{},...e._meta?.alwith?.preview?{preview:e._meta.alwith.preview}:{}}})}export{c as elicitationFields,p as elicitationLabels,s as elicitationOptions,o as isMultiSelect};
1
+ function c(t){return Object.entries(t.properties??{}).map(([n,i])=>({key:n,property:i}))}function s(t){let{title:n,description:i}=t;return{title:n??void 0,description:i??void 0}}function r(t){return t.type==="array"}function a(t){return(r(t)?t.items?.oneOf??[]:t.oneOf??[]).map((i)=>{let e=i,o=e.const??e.title??"";return{value:o,label:e.title??o,...e.description?{description:e.description}:{},...e._meta?.alwith?.preview?{preview:e._meta.alwith.preview}:{}}})}export{c as elicitationFields,s as elicitationLabels,a as elicitationOptions,r as isMultiSelect};
@@ -1 +1 @@
1
- import{jsx as r,jsxs as u}from"react/jsx-runtime";import{autoUpdate as S}from"@floating-ui/dom";import{CheckCheckIcon as z,CheckIcon as _,ShieldXIcon as M,XIcon as O}from"lucide-react";import{useCallback as U,useEffect as v,useId as W,useLayoutEffect as I,useRef as X,useState as p}from"react";import{createPortal as B}from"react-dom";import{cn as N}from"cn";import{sortPermissionOptions as H}from"./permission-options.js";var L={allow_once:{icon:_},allow_always:{icon:z},reject_once:{icon:O},reject_always:{icon:M}};function R({requestId:f,options:j,title:D,children:E,total:w=1,alwaysLabel:A="always",autoFocus:y="always",anchorRef:n,onRespond:i}){let x=W(),[l,b]=p(0),[s,g]=p(null),[a,C]=p(null),k=X(null),c=H(j);v(()=>{b(0)},[f]),v(()=>{let e=document.activeElement;if(y==="always"||e===null||e===document.body)k.current?.focus()},[f,a,y]);let d=U(()=>{let e=n?.current;if(!e)return;let t=e.getBoundingClientRect();if(t.width===0){let o=Math.min(640,window.innerWidth*0.9);g({left:(window.innerWidth-o)/2,width:o,bottom:24});return}g({left:t.left,width:t.width,bottom:window.innerHeight-t.bottom+20})},[n]);if(I(()=>{if(!n)return;let e=0,t=()=>{if(n.current)d();else e=requestAnimationFrame(t)};return t(),()=>cancelAnimationFrame(e)},[f,n,d]),I(()=>{let e=n?.current;if(!e||!a)return;return S(e,a,d,{animationFrame:!0})},[n,a,d]),n&&!s)return null;let h=u("div",{ref:C,"data-overlay":"permission-request",className:N("bg-card border-border overflow-hidden rounded-lg border",n&&"fixed z-50"),style:n&&s?{left:s.left,width:s.width,bottom:s.bottom}:void 0,children:[u("div",{className:"border-border border-b px-3 py-2",children:[u("div",{className:"flex items-center justify-between gap-2",children:[r("div",{id:x,className:"text-foreground text-sm font-medium",children:D}),w>1&&r("span",{className:"text-muted-foreground shrink-0 text-xs",children:`1 / ${w}`})]}),E]}),r("div",{role:"listbox","aria-labelledby":x,tabIndex:0,ref:k,onKeyDown:(e)=>{let t=c.length;if(t===0&&e.key!=="Escape")return;if(e.key==="ArrowDown"||e.key==="ArrowUp")e.preventDefault(),b((o)=>e.key==="ArrowDown"?(o+1)%t:(o-1+t)%t);else if(e.key==="Enter")e.preventDefault(),i(c[l].optionId);else if(e.key==="Escape")e.preventDefault(),i(null);else if(/^[1-9]$/.test(e.key)&&Number(e.key)<=t)e.preventDefault(),i(c[Number(e.key)-1].optionId)},className:"outline-none",children:c.map((e,t)=>{let o=e.kind??"allow_once",P=L[o]?.icon??_,F=o==="allow_always"||o==="reject_always",K=o==="reject_once"||o==="reject_always";return u("div",{role:"option",tabIndex:-1,"aria-selected":t===l,title:e.description,onClick:()=>void i(e.optionId),onKeyDown:(m)=>{if(m.key==="Enter"||m.key===" ")m.preventDefault(),m.stopPropagation(),i(e.optionId)},className:N("flex cursor-pointer items-center gap-2 px-3 py-1.5 text-sm select-none",t===l?"bg-ring text-accent-foreground":"text-foreground",K&&t!==l&&"text-muted-foreground"),children:[r("span",{className:"min-w-3 text-xs opacity-70",children:t+1}),r(P,{className:"size-3.5 shrink-0 opacity-80"}),r("span",{className:"min-w-0 flex-1 truncate",children:e.name}),F&&r("span",{className:"bg-muted text-muted-foreground rounded px-1.5 py-0.5 text-[10px] tracking-wide uppercase",children:A})]},e.optionId)})})]});return n?B(h,document.body):h}export{R as PermissionView};
1
+ import{jsx as r,jsxs as u}from"react/jsx-runtime";import{autoUpdate as S}from"@floating-ui/dom";import{cn as v}from"cn";import{CheckCheckIcon as z,CheckIcon as _,ShieldXIcon as M,XIcon as O}from"lucide-react";import{useCallback as U,useEffect as I,useId as W,useLayoutEffect as N,useRef as X,useState as p}from"react";import{createPortal as B}from"react-dom";import{sortPermissionOptions as H}from"./permission-options.js";var L={allow_once:{icon:_},allow_always:{icon:z},reject_once:{icon:O},reject_always:{icon:M}};function R({requestId:f,options:j,title:D,children:E,total:w=1,alwaysLabel:A="always",autoFocus:y="always",anchorRef:n,onRespond:i}){let x=W(),[l,b]=p(0),[s,g]=p(null),[a,C]=p(null),k=X(null),c=H(j);I(()=>{b(0)},[f]),I(()=>{let e=document.activeElement;if(y==="always"||e===null||e===document.body)k.current?.focus()},[f,a,y]);let d=U(()=>{let e=n?.current;if(!e)return;let t=e.getBoundingClientRect();if(t.width===0){let o=Math.min(640,window.innerWidth*0.9);g({left:(window.innerWidth-o)/2,width:o,bottom:24});return}g({left:t.left,width:t.width,bottom:window.innerHeight-t.bottom+20})},[n]);if(N(()=>{if(!n)return;let e=0,t=()=>{if(n.current)d();else e=requestAnimationFrame(t)};return t(),()=>cancelAnimationFrame(e)},[f,n,d]),N(()=>{let e=n?.current;if(!e||!a)return;return S(e,a,d,{animationFrame:!0})},[n,a,d]),n&&!s)return null;let h=u("div",{ref:C,"data-overlay":"permission-request",className:v("bg-card border-border overflow-hidden rounded-lg border",n&&"fixed z-50"),style:n&&s?{left:s.left,width:s.width,bottom:s.bottom}:void 0,children:[u("div",{className:"border-border border-b px-3 py-2",children:[u("div",{className:"flex items-center justify-between gap-2",children:[r("div",{id:x,className:"text-foreground text-sm font-medium",children:D}),w>1&&r("span",{className:"text-muted-foreground shrink-0 text-xs",children:`1 / ${w}`})]}),E]}),r("div",{role:"listbox","aria-labelledby":x,tabIndex:0,ref:k,onKeyDown:(e)=>{let t=c.length;if(t===0&&e.key!=="Escape")return;if(e.key==="ArrowDown"||e.key==="ArrowUp")e.preventDefault(),b((o)=>e.key==="ArrowDown"?(o+1)%t:(o-1+t)%t);else if(e.key==="Enter")e.preventDefault(),i(c[l].optionId);else if(e.key==="Escape")e.preventDefault(),i(null);else if(/^[1-9]$/.test(e.key)&&Number(e.key)<=t)e.preventDefault(),i(c[Number(e.key)-1].optionId)},className:"outline-none",children:c.map((e,t)=>{let o=e.kind??"allow_once",P=L[o]?.icon??_,F=o==="allow_always"||o==="reject_always",K=o==="reject_once"||o==="reject_always";return u("div",{role:"option",tabIndex:-1,"aria-selected":t===l,title:e.description,onClick:()=>void i(e.optionId),onKeyDown:(m)=>{if(m.key==="Enter"||m.key===" ")m.preventDefault(),m.stopPropagation(),i(e.optionId)},className:v("flex cursor-pointer items-center gap-2 px-3 py-1.5 text-sm select-none",t===l?"bg-ring text-accent-foreground":"text-foreground",K&&t!==l&&"text-muted-foreground"),children:[r("span",{className:"min-w-3 text-xs opacity-70",children:t+1}),r(P,{className:"size-3.5 shrink-0 opacity-80"}),r("span",{className:"min-w-0 flex-1 truncate",children:e.name}),F&&r("span",{className:"bg-muted text-muted-foreground rounded px-1.5 py-0.5 text-[10px] tracking-wide uppercase",children:A})]},e.optionId)})})]});return n?B(h,document.body):h}export{R as PermissionView};
@@ -1,4 +1,4 @@
1
- import type * as acp from "@agentclientprotocol/sdk/experimental/v2";
1
+ import type * as acp from "@agentclientprotocol/sdk/experimental/v2/unstable";
2
2
  type FormValue = acp.ElicitationContentValue | undefined;
3
3
  interface Option {
4
4
  value: string;
@@ -1 +1 @@
1
- import{jsx as i,jsxs as a}from"react/jsx-runtime";import{useEffect as w,useMemo as F,useState as N}from"react";import{Button as y}from"../ui/button.js";import{Checkbox as S}from"../ui/checkbox.js";import{Dialog as C,DialogContent as D,DialogDescription as j,DialogFooter as q,DialogHeader as E,DialogTitle as P}from"../ui/dialog.js";import{Field as G,FieldDescription as p,FieldGroup as I,FieldLabel as K,FieldLegend as x,FieldSet as b}from"../ui/field.js";import{Input as L}from"../ui/input.js";import{Label as V}from"../ui/label.js";import{RadioGroup as _,RadioGroupItem as B}from"../ui/radio-group.js";import{Switch as T}from"../ui/switch.js";import{Textarea as H}from"../ui/textarea.js";import{isArrayProperty as A,isBooleanProperty as O,isNumberProperty as M,isStringProperty as R}from"@alwith/api";function z(n){if(!R(n))return null;if(n.oneOf&&n.oneOf.length>0)return n.oneOf.map((e)=>({value:e.const,label:e.title??e.const,...e.description?{description:e.description}:{}}));if(n.enum&&n.enum.length>0)return n.enum.map((e)=>({value:e,label:e}));return null}function J(n){let e=n,t=e._meta?.alwith?.options;if(Array.isArray(t)&&Array.isArray(e.enum))return t.map((r)=>({value:r.const,label:r.title,...r.description?{description:r.description}:{}}));if(Array.isArray(e.enum))return e.enum.map((r)=>({value:String(r),label:String(r)}));if(Array.isArray(e.oneOf))return e.oneOf.map((r)=>({value:r.const,label:r.title,...r.description?{description:r.description}:{}}));return null}function Q(n){let e=new Set(n.required??[]);return Object.entries(n.properties??{}).map(([t,r])=>({key:t,property:r,title:r.title??t,description:r.description??null,required:e.has(t),options:z(r),multiOptions:A(r)?J(r.items):null}))}function v(n){let e={};for(let t of n){let r=t.property.default;if(r!==void 0&&r!==null)e[t.key]=r;else if(t.options)e[t.key]=t.options[0].value;else if(O(t.property))e[t.key]=!1;else if(A(t.property))e[t.key]=[]}return e}function U(n,e){if(n.multiOptions)return Array.isArray(e)&&e.length>0;if(!n.required)return!0;return e!==void 0&&e!==""&&!(Array.isArray(e)&&e.length===0)}function k({id:n,label:e,description:t,control:r}){return a("div",{className:"hover:bg-muted/40 flex items-center gap-2 rounded-sm px-1.5 py-1",children:[r,a(V,{htmlFor:n,className:"min-w-0 flex-1 cursor-pointer font-normal",children:[i("div",{className:"text-foreground text-sm",children:e}),t&&i("div",{className:"text-muted-foreground text-xs",children:t})]})]})}function W({id:n,field:e,value:t,onChange:r}){if(e.multiOptions){let l=new Set(Array.isArray(t)?t:[]);return a(b,{children:[i(x,{variant:"label",children:e.title}),e.description&&i(p,{children:e.description}),i("div",{className:"flex flex-col gap-1",children:e.multiOptions.map((s)=>{let c=`${n}:${s.value}`;return i(k,{id:c,...s,control:i(S,{id:c,checked:l.has(s.value),onCheckedChange:(d)=>{let u=new Set(l);if(d)u.add(s.value);else u.delete(s.value);r([...u])}})},s.value)})})]})}if(e.options)return a(b,{children:[i(x,{variant:"label",children:e.title}),e.description&&i(p,{children:e.description}),i(_,{value:typeof t==="string"?t:"",onValueChange:(l)=>r(String(l)),className:"flex flex-col gap-1",children:e.options.map((l)=>{let s=`${n}:${l.value}`;return i(k,{id:s,...l,control:i(B,{value:l.value,id:s})},l.value)})})]});return a(G,{children:[i(K,{htmlFor:n,children:e.title}),O(e.property)?i(T,{id:n,checked:t===!0,onCheckedChange:(l)=>r(l)}):M(e.property)?i(L,{id:n,type:"number",required:e.required,value:typeof t==="number"?t:"",onChange:(l)=>r(l.target.value===""?void 0:Number(l.target.value))}):i(H,{id:n,rows:2,required:e.required,value:typeof t==="string"?t:"",onChange:(l)=>r(l.target.value)}),e.description&&i(p,{children:e.description})]})}function ce({requestId:n,schema:e,message:t,total:r,t:l,onRespond:s}){let c=F(()=>Q(e),[e]),[d,u]=N(()=>v(c));w(()=>u(v(c)),[n,c]);let h=c.every((o)=>U(o,d[o.key])),g=()=>{if(!h)return;let o={};for(let[f,m]of Object.entries(d))if(m!==void 0)o[f]=m;s({action:"accept",content:o})};return i(C,{open:!0,onOpenChange:(o)=>!o&&s({action:"cancel"}),children:a(D,{className:"flex max-h-[80vh] flex-col gap-4 sm:max-w-lg",onKeyDown:(o)=>{if(o.key==="Enter"&&(o.metaKey||o.ctrlKey))o.preventDefault(),g()},children:[a(E,{children:[a("div",{className:"flex items-center justify-between gap-2 pe-8",children:[i(P,{children:e.title??l("approval.needed")}),r>1&&i("span",{className:"text-muted-foreground shrink-0 text-xs",children:`1 / ${r}`})]}),i(j,{children:t})]}),i("div",{className:"min-h-0 flex-1 overflow-y-auto",children:i(I,{children:c.map((o)=>i(W,{id:`${n}:${o.key}`,field:o,value:d[o.key],onChange:(f)=>u((m)=>({...m,[o.key]:f}))},o.key))})}),a(q,{children:[i(y,{variant:"ghost",onClick:()=>s({action:"decline"}),children:l("actions.decline")}),i(y,{disabled:!h,onClick:g,children:l("actions.submit")})]})]})})}export{ce as SchemaElicitationForm,Q as elicitationFields,v as initialValues,U as isAnswered};
1
+ import{jsx as i,jsxs as a}from"react/jsx-runtime";import{isArrayProperty as A,isBooleanProperty as O,isNumberProperty as w,isStringProperty as F}from"@alwith/api";import{useEffect as N,useMemo as S,useState as C}from"react";import{Button as y}from"../ui/button.js";import{Checkbox as D}from"../ui/checkbox.js";import{Dialog as j,DialogContent as q,DialogDescription as E,DialogFooter as P,DialogHeader as G,DialogTitle as I}from"../ui/dialog.js";import{Field as K,FieldDescription as p,FieldGroup as L,FieldLabel as V,FieldLegend as x,FieldSet as b}from"../ui/field.js";import{Input as _}from"../ui/input.js";import{Label as B}from"../ui/label.js";import{RadioGroup as T,RadioGroupItem as H}from"../ui/radio-group.js";import{Switch as M}from"../ui/switch.js";import{Textarea as R}from"../ui/textarea.js";function z(n){if(!F(n))return null;if(n.oneOf&&n.oneOf.length>0)return n.oneOf.map((e)=>({value:e.const,label:e.title??e.const,...e.description?{description:e.description}:{}}));if(n.enum&&n.enum.length>0)return n.enum.map((e)=>({value:e,label:e}));return null}function J(n){let e=n,t=e._meta?.alwith?.options;if(Array.isArray(t)&&Array.isArray(e.enum))return t.map((r)=>({value:r.const,label:r.title,...r.description?{description:r.description}:{}}));if(Array.isArray(e.enum))return e.enum.map((r)=>({value:String(r),label:String(r)}));if(Array.isArray(e.oneOf))return e.oneOf.map((r)=>({value:r.const,label:r.title,...r.description?{description:r.description}:{}}));return null}function Q(n){let e=new Set(n.required??[]);return Object.entries(n.properties??{}).map(([t,r])=>({key:t,property:r,title:r.title??t,description:r.description??null,required:e.has(t),options:z(r),multiOptions:A(r)?J(r.items):null}))}function v(n){let e={};for(let t of n){let r=t.property.default;if(r!==void 0&&r!==null)e[t.key]=r;else if(t.options)e[t.key]=t.options[0].value;else if(O(t.property))e[t.key]=!1;else if(A(t.property))e[t.key]=[]}return e}function U(n,e){if(n.multiOptions)return Array.isArray(e)&&e.length>0;if(!n.required)return!0;return e!==void 0&&e!==""&&!(Array.isArray(e)&&e.length===0)}function k({id:n,label:e,description:t,control:r}){return a("div",{className:"hover:bg-muted/40 flex items-center gap-2 rounded-sm px-1.5 py-1",children:[r,a(B,{htmlFor:n,className:"min-w-0 flex-1 cursor-pointer font-normal",children:[i("div",{className:"text-foreground text-sm",children:e}),t&&i("div",{className:"text-muted-foreground text-xs",children:t})]})]})}function W({id:n,field:e,value:t,onChange:r}){if(e.multiOptions){let l=new Set(Array.isArray(t)?t:[]);return a(b,{children:[i(x,{variant:"label",children:e.title}),e.description&&i(p,{children:e.description}),i("div",{className:"flex flex-col gap-1",children:e.multiOptions.map((s)=>{let c=`${n}:${s.value}`;return i(k,{id:c,...s,control:i(D,{id:c,checked:l.has(s.value),onCheckedChange:(d)=>{let u=new Set(l);if(d)u.add(s.value);else u.delete(s.value);r([...u])}})},s.value)})})]})}if(e.options)return a(b,{children:[i(x,{variant:"label",children:e.title}),e.description&&i(p,{children:e.description}),i(T,{value:typeof t==="string"?t:"",onValueChange:(l)=>r(String(l)),className:"flex flex-col gap-1",children:e.options.map((l)=>{let s=`${n}:${l.value}`;return i(k,{id:s,...l,control:i(H,{value:l.value,id:s})},l.value)})})]});return a(K,{children:[i(V,{htmlFor:n,children:e.title}),O(e.property)?i(M,{id:n,checked:t===!0,onCheckedChange:(l)=>r(l)}):w(e.property)?i(_,{id:n,type:"number",required:e.required,value:typeof t==="number"?t:"",onChange:(l)=>r(l.target.value===""?void 0:Number(l.target.value))}):i(R,{id:n,rows:2,required:e.required,value:typeof t==="string"?t:"",onChange:(l)=>r(l.target.value)}),e.description&&i(p,{children:e.description})]})}function ce({requestId:n,schema:e,message:t,total:r,t:l,onRespond:s}){let c=S(()=>Q(e),[e]),[d,u]=C(()=>v(c));N(()=>u(v(c)),[n,c]);let h=c.every((o)=>U(o,d[o.key])),g=()=>{if(!h)return;let o={};for(let[f,m]of Object.entries(d))if(m!==void 0)o[f]=m;s({action:"accept",content:o})};return i(j,{open:!0,onOpenChange:(o)=>!o&&s({action:"cancel"}),children:a(q,{className:"flex max-h-[80vh] flex-col gap-4 sm:max-w-lg",onKeyDown:(o)=>{if(o.key==="Enter"&&(o.metaKey||o.ctrlKey))o.preventDefault(),g()},children:[a(G,{children:[a("div",{className:"flex items-center justify-between gap-2 pe-8",children:[i(I,{children:e.title??l("approval.needed")}),r>1&&i("span",{className:"text-muted-foreground shrink-0 text-xs",children:`1 / ${r}`})]}),i(E,{children:t})]}),i("div",{className:"min-h-0 flex-1 overflow-y-auto",children:i(L,{children:c.map((o)=>i(W,{id:`${n}:${o.key}`,field:o,value:d[o.key],onChange:(f)=>u((m)=>({...m,[o.key]:f}))},o.key))})}),a(P,{children:[i(y,{variant:"ghost",onClick:()=>s({action:"decline"}),children:l("actions.decline")}),i(y,{disabled:!h,onClick:g,children:l("actions.submit")})]})]})})}export{ce as SchemaElicitationForm,Q as elicitationFields,v as initialValues,U as isAnswered};
@@ -1,6 +1,6 @@
1
- import{jsx as n,jsxs as p,Fragment as j}from"react/jsx-runtime";import{useActivityHost as L,ActivityMarkdown as Q}from"../activity-host.js";import{BotIcon as se,CheckIcon as de,CopyIcon as ce}from"lucide-react";import{Fragment as le,useEffect as A,useRef as I,useState as D}from"react";import{cn as C}from"cn";import{formatModelName as q}from"../lib/model-name.js";import{describeToolUse as O}from"../lib/stream-style.js";import{useCodexDisclosureState as E}from"./disclosure-state.js";import{CodexPlan as ue}from"./plan.js";function P(e,t){let[i,a]=D(()=>({key:e,mounted:t})),r=t||i.key===e&&i.mounted;if(i.key!==e||i.mounted!==r)a({key:e,mounted:r});return r}var z=new WeakMap,U=1;function M(e){if(e.type==="tool_use"||e.type==="subagent"||e.type==="collab")return`${e.type}:${e.id}`;if(e.type==="thinking"&&e.id!==void 0)return`thinking:${e.id}`;let t=z.get(e);if(t!==void 0)return`${e.type}:${t}`;let i=U;return U+=1,z.set(e,i),`${e.type}:${i}`}function w(e){switch(e){case"pending":case"in_progress":return!0;case"completed":case"failed":case"cancelled":case"interrupted":return!1;default:throw Error(`Unknown ACP tool status: ${e}`)}}function W(e,t){let i=Math.max(0,Math.round(e/1000)),a=Math.floor(i/3600),r=Math.floor(i%3600/60),o=i%60;if(o>=60)r+=Math.floor(o/60),o%=60;if(r>=60)a+=Math.floor(r/60),r%=60;let d=Intl.DurationFormat;if(d)try{return new d(t,{style:"narrow"}).format({hours:a,minutes:r,seconds:a>0?0:o})}catch{}if(a>0)return r>0?`${a}h ${r}m`:`${a}h`;if(r>0)return o>0?`${r}m ${o}s`:`${r}m`;return`${o}s`}var me="M7.52925 3.7793C7.75652 3.55203 8.10803 3.52383 8.36616 3.69434L8.47065 3.7793L14.2207 9.5293C14.4804 9.789 14.4804 10.211 14.2207 10.4707L8.47065 16.2207C8.21095 16.4804 7.78895 16.4804 7.52925 16.2207C7.26955 15.961 7.26955 15.539 7.52925 15.2793L12.8085 10L7.52925 4.7207L7.44429 4.61621C7.27378 4.35808 7.30198 4.00657 7.52925 3.7793Z";function _({expanded:e,className:t}){return n("svg",{className:C("codex-activity-disclosure",e&&"codex-activity-disclosure-expanded",t),viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:n("path",{d:me})})}function pe(){return n("svg",{className:"codex-activity-icon",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:n("path",{d:"M16.3965 5.01128C16.3963 4.93399 16.3489 4.87691 16.293 4.85406L16.2354 4.84332C13.9306 4.91764 12.5622 5.32101 10.665 6.34722V16.3716C11.3851 15.9994 12.0688 15.7115 12.7861 15.5015C13.8286 15.1965 14.9113 15.0633 16.2402 15.0435L16.2979 15.0308C16.353 15.0063 16.3965 14.9483 16.3965 14.8755V5.01128ZM3.54492 14.8765C3.54492 14.9725 3.62159 15.0422 3.70117 15.0435L4.19629 15.0562C5.94062 15.1247 7.26036 15.4201 8.65918 16.0484C8.05544 15.1706 7.14706 14.436 6.17871 14.1109V14.1099C5.56757 13.9045 5.16816 13.3314 5.16797 12.6988V4.98882C4.86679 4.93786 4.60268 4.8999 4.28223 4.87457L3.72754 4.84429C3.62093 4.84079 3.54505 4.92417 3.54492 5.01226V14.8765ZM17.7266 14.8755C17.7266 15.6314 17.1607 16.2751 16.4121 16.3628L16.2598 16.3736C15.0122 16.3922 14.0555 16.5159 13.1602 16.7779C12.2629 17.0404 11.3966 17.4508 10.3369 18.0738C10.129 18.1959 9.87099 18.1958 9.66309 18.0738C7.71455 16.9283 6.31974 16.4689 4.12988 16.3853L3.68164 16.3736C2.85966 16.3614 2.21484 15.6838 2.21484 14.8765V5.01226C2.21497 4.15391 2.93263 3.4871 3.77246 3.51519L4.39844 3.54937C4.67996 3.57191 4.92258 3.60421 5.16797 3.64214V2.51031C5.16797 1.44939 6.29018 0.645615 7.31055 1.15679L7.31152 1.15582C8.78675 1.89511 10.0656 3.33006 10.5352 4.91461C12.3595 3.98907 13.8688 3.58817 16.1924 3.51324L16.3506 3.51714C17.1285 3.5741 17.7264 4.23496 17.7266 5.01128V14.8755ZM6.49805 12.6988C6.49824 12.7723 6.5442 12.8296 6.60254 12.8492L6.96289 12.9859C7.85245 13.3586 8.68125 13.9846 9.33496 14.7496V5.5816C9.08794 4.37762 8.13648 3.1566 6.95801 2.47613L6.71582 2.34527C6.67779 2.32617 6.6337 2.32502 6.58301 2.35796C6.52946 2.39279 6.49805 2.44863 6.49805 2.51031V12.6988Z"})})}function fe(){return n("svg",{className:"codex-activity-icon",viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:n("path",{d:"M7.33057 1.98535C10.2484 1.98535 12.6136 4.3508 12.6138 7.26855C12.6138 8.58031 12.1346 9.77942 11.3433 10.7031L13.9897 13.3496C14.1655 13.5253 14.1655 13.8106 13.9897 13.9863C13.814 14.1621 13.5288 14.1621 13.353 13.9863L10.7017 11.335C9.78678 12.0942 8.61243 12.5518 7.33057 12.5518C4.41281 12.5516 2.04736 10.1864 2.04736 7.26855C2.04754 4.35091 4.41292 1.98553 7.33057 1.98535ZM7.33057 2.88574C4.90998 2.88592 2.94793 4.84796 2.94775 7.26855C2.94775 9.68929 4.90987 11.6522 7.33057 11.6523C9.75141 11.6523 11.7144 9.6894 11.7144 7.26855C11.7142 4.84786 9.75131 2.88574 7.33057 2.88574Z"})})}function xe(){return p("svg",{className:"codex-activity-icon",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:[n("path",{d:"M6.19629 7.86231C6.42357 7.63534 6.7752 7.60692 7.0332 7.77734L7.1377 7.86231L8.80371 9.5293C9.06329 9.78889 9.06307 10.21 8.80371 10.4697L7.1377 12.1367C6.878 12.3964 6.45599 12.3964 6.19629 12.1367C5.93686 11.8771 5.93697 11.456 6.19629 11.1963L7.39258 9.99902L6.19629 8.80371L6.11133 8.69922C5.94087 8.4411 5.96904 8.08955 6.19629 7.86231Z"}),n("path",{d:"M13.4668 11.0156C13.7699 11.0776 13.998 11.3456 13.998 11.667C13.9979 11.9883 13.7698 12.2564 13.4668 12.3184L13.333 12.332H10.833C10.466 12.3319 10.1682 12.034 10.168 11.667C10.168 11.2998 10.4659 11.0021 10.833 11.002H13.333L13.4668 11.0156Z"}),n("path",{d:"M12.6602 2.66504C13.3492 2.66504 13.9062 2.66439 14.3564 2.70117C14.8142 2.73859 15.2201 2.81796 15.5967 3.00977C16.1922 3.31321 16.677 3.79805 16.9805 4.39356C17.1722 4.77014 17.2517 5.17604 17.2891 5.63379C17.3258 6.08402 17.3252 6.64102 17.3252 7.33008V12.6602C17.3252 13.3492 17.3258 13.9062 17.2891 14.3564C17.2516 14.8142 17.1723 15.2201 16.9805 15.5967C16.677 16.1922 16.1922 16.677 15.5967 16.9805C15.2201 17.1723 14.8142 17.2516 14.3564 17.2891C13.9062 17.3258 13.3492 17.3252 12.6602 17.3252H7.33008C6.64102 17.3252 6.08402 17.3258 5.63379 17.2891C5.17604 17.2517 4.77014 17.1722 4.39356 16.9805C3.79805 16.677 3.31321 16.1922 3.00977 15.5967C2.81796 15.2201 2.73859 14.8142 2.70117 14.3564C2.66439 13.9062 2.66504 13.3492 2.66504 12.6602V7.33008C2.66504 6.64101 2.66439 6.08402 2.70117 5.63379C2.73858 5.17601 2.81797 4.77016 3.00977 4.39356C3.31321 3.79802 3.79802 3.31321 4.39356 3.00977C4.77016 2.81797 5.17601 2.73858 5.63379 2.70117C6.08402 2.66439 6.64101 2.66504 7.33008 2.66504H12.6602ZM7.33008 3.99512C6.61907 3.99512 6.1257 3.99601 5.74219 4.02734C5.3665 4.05804 5.15508 4.11481 4.99707 4.19531C4.65183 4.37124 4.37124 4.65183 4.19531 4.99707C4.11481 5.15508 4.05805 5.3665 4.02734 5.74219C3.99601 6.1257 3.99512 6.61908 3.99512 7.33008V12.6602C3.99512 13.3711 3.99601 13.8646 4.02734 14.248C4.05805 14.6237 4.11481 14.8352 4.19531 14.9932C4.37124 15.3384 4.65186 15.619 4.99707 15.7949C5.15507 15.8754 5.36654 15.9322 5.74219 15.9629C6.1257 15.9942 6.61908 15.9951 7.33008 15.9951H12.6602C13.3711 15.9951 13.8646 15.9942 14.248 15.9629C14.6237 15.9322 14.8352 15.8754 14.9932 15.7949C15.3384 15.619 15.619 15.3384 15.7949 14.9932C15.8754 14.8352 15.9322 14.6237 15.9629 14.248C15.9942 13.8646 15.9951 13.3711 15.9951 12.6602V7.33008C15.9951 6.61908 15.9942 6.1257 15.9629 5.74219C15.9322 5.36654 15.8754 5.15507 15.7949 4.99707C15.619 4.65186 15.3384 4.37124 14.9932 4.19531C14.8352 4.11481 14.6237 4.05805 14.248 4.02734C13.8646 3.99601 13.3711 3.99512 12.6602 3.99512H7.33008Z"})]})}function ge(){return n("svg",{className:"codex-activity-icon",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:n("path",{d:"M11.3312 4.20472C12.7488 2.92391 14.9377 2.96644 16.3039 4.33265L16.4318 4.46742C17.6713 5.8393 17.6713 7.93343 16.4318 9.30531L16.3039 9.44007L10.0119 15.7311C9.68839 16.0546 9.45384 16.2917 9.22185 16.4821L8.98748 16.6588C8.78233 16.799 8.56429 16.9196 8.33709 17.0192L8.10759 17.1119C7.92582 17.1785 7.73843 17.2266 7.52166 17.2711L6.75701 17.4069L4.36345 17.8053C4.22059 17.8291 4.06914 17.8552 3.9406 17.8649C3.84183 17.8723 3.70833 17.875 3.56267 17.8395L3.41423 17.7907C3.19121 17.695 3.00747 17.5271 2.89177 17.316L2.84588 17.2223C2.75958 17.0209 2.76174 16.8276 2.77166 16.6959C2.78136 16.5674 2.80742 16.4159 2.83123 16.2731L3.22966 13.8795L3.36443 13.1149C3.40899 12.898 3.45795 12.7108 3.52459 12.5289L3.61736 12.2985C3.71691 12.0715 3.83772 11.854 3.97771 11.6491L4.15349 11.4147C4.34392 11.1825 4.58171 10.9484 4.90545 10.6246L11.1965 4.33265L11.3312 4.20472ZM5.84588 11.5651C5.49671 11.9142 5.31258 12.0998 5.1867 12.2526L5.07537 12.3991C4.98194 12.5358 4.90157 12.6812 4.83513 12.8327L4.77361 12.9869C4.73328 13.0971 4.70248 13.2125 4.66814 13.3815L4.54119 14.0983L4.14275 16.4918L4.14177 16.4938H4.1447L6.53826 16.0944L7.25505 15.9684C7.42406 15.9341 7.53946 15.9033 7.64959 15.8629L7.80291 15.8014C7.95461 15.7349 8.09953 15.6538 8.2365 15.5602L8.38396 15.4498C8.53674 15.3239 8.72231 15.1398 9.07146 14.7907L14.0588 9.80238L10.8332 6.57679L5.84588 11.5651ZM15.3635 5.27308C14.5281 4.43776 13.2058 4.38573 12.3097 5.11683L12.1369 5.27308L11.7736 5.63636L15.0002 8.86195L15.3635 8.49964L15.5197 8.32581C16.2015 7.48961 16.2015 6.28311 15.5197 5.44691L15.3635 5.27308Z"})})}function he(){return n("svg",{className:"codex-activity-icon",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:n("path",{d:"M16.8347 7.91699C16.8347 7.76279 16.8266 7.61021 16.8123 7.45996L15.4705 8.80371C14.2903 9.98388 12.3762 9.98388 11.1961 8.80371C10.016 7.62352 10.0159 5.70942 11.1961 4.5293L12.5378 3.18652C12.3885 3.17238 12.237 3.16505 12.0837 3.16504C9.45947 3.16504 7.33179 5.29272 7.33179 7.91699C7.33184 8.56608 7.46162 9.18329 7.69605 9.74512C7.79981 9.9939 7.74311 10.2811 7.5525 10.4717L3.59547 14.4287C3.0498 14.9744 3.04991 15.8586 3.59547 16.4043L3.70191 16.501C4.25076 16.9483 5.05957 16.9158 5.57105 16.4043L9.52906 12.4473L9.60426 12.3828C9.79018 12.2455 10.0369 12.2131 10.2546 12.3037C10.8166 12.5382 11.4345 12.668 12.0837 12.668C14.7078 12.6678 16.8345 10.541 16.8347 7.91699ZM18.1648 7.91699C18.1646 11.2755 15.4423 13.9979 12.0837 13.998C11.4151 13.998 10.7708 13.8886 10.1677 13.6885L6.51246 17.3457C5.51389 18.3443 3.93332 18.406 2.86207 17.5322L2.65504 17.3457C1.58992 16.2806 1.58992 14.5534 2.65504 13.4883L6.31031 9.83203C6.1104 9.22921 6.00175 8.58526 6.00172 7.91699C6.00172 4.55818 8.72494 1.83496 12.0837 1.83496C12.7838 1.835 13.458 1.95316 14.0857 2.17188L14.1638 2.20508C14.3404 2.29325 14.4697 2.45713 14.5144 2.65234C14.5653 2.87533 14.4984 3.10876 14.3367 3.27051L12.1375 5.4707C11.4767 6.13148 11.4767 7.20251 12.1375 7.86328C12.7983 8.52373 13.8694 8.52395 14.53 7.86328L16.7293 5.66309L16.7937 5.60742C16.9499 5.48687 17.1532 5.44067 17.3484 5.48535C17.5714 5.53648 17.7526 5.69898 17.8279 5.91504C18.0466 6.54272 18.1648 7.21689 18.1648 7.91699Z"})})}function X({block:e}){if(e.type!=="tool_use")return null;let t=O(e).category;if(t==="read")return n(pe,{});if(t==="search"||t==="fetch")return n(fe,{});if(t==="execute")return n(xe,{});if(t==="edit")return n(ge,{});return n(he,{})}function T(e,t){let i=e.rawInput[t];return typeof i==="string"&&i.length>0?i:void 0}function Ce(e){return O(e).target}function R(e){return e.name.startsWith("mcp__")||e.name.startsWith("mcp_")}function Y(e,t){let{category:i}=O(e),a=Ce(e),r=w(e.status);if(R(e))return{leading:e.title};if(i==="execute"){let o=T(e,"command")?.split(`
2
- `)[0]??a;return o?{leading:t(r?"stream.codex.running":"stream.codex.ran"),trailing:o}:{leading:t(r?"stream.codex.runningCommand":"stream.codex.ranCommandGeneric")}}if(i==="search"){let o=T(e,"pattern")??T(e,"query")??a;return o?{leading:t(r?"stream.codex.searching":"stream.codex.searched"),trailing:t("stream.codex.forDetail",{detail:o})}:{leading:t(r?"stream.codex.searchingFiles":"stream.codex.searchedFiles")}}if(i==="fetch"){let o=T(e,"query")??T(e,"url")??a;return o?{leading:t(r?"stream.codex.searchingWeb":"stream.codex.searchedWeb"),trailing:t("stream.codex.forDetail",{detail:o})}:{leading:t(r?"stream.codex.searchingWeb":"stream.codex.searchedWeb")}}if(i==="read")return a?{leading:t("stream.codex.readLabel"),trailing:a}:{leading:t("stream.codex.readFiles")};if(i==="edit")return a?{leading:t(r?"stream.codex.editingLabel":"stream.codex.editedLabel"),trailing:a}:{leading:t(r?"stream.codex.editingFiles":"stream.codex.editedFiles")};if(i==="delete")return a?{leading:t(r?"stream.codex.deletingLabel":"stream.codex.deletedLabel"),trailing:a}:{leading:t(r?"stream.codex.deletingFiles":"stream.codex.deletedFiles")};if(i==="move")return a?{leading:t(r?"stream.codex.movingLabel":"stream.codex.movedLabel"),trailing:a}:{leading:t(r?"stream.codex.movingFiles":"stream.codex.movedFiles")};return{leading:e.title}}function ye(e,t){let i=Y(e,t);return i.trailing===void 0?i.leading:`${i.leading} ${i.trailing}`}function ve(e){return e.map((t)=>{if(t.type!=="content")return"";let i=t.content;return i.type==="text"?i.text:""}).filter(Boolean).join(`
3
- `).trim()}function we(e){return e.flatMap((t)=>{if(t.type!=="content")return[];let i=t.content;return i.type==="image"?[{data:i.data,mimeType:i.mimeType}]:[]})}function Le(e){return e.flatMap((t)=>{if(t.type!=="content")return[];let i=t.content;return i.type==="audio"?[{data:i.data,mimeType:i.mimeType}]:[]})}function Ne(e){if(typeof e==="string"&&e.length>0)return e;return}function $e(e){return e.type==="diff"}function Me(e){let t=e.content.find($e);if(t===void 0)return;return t.changes.map((i)=>`${i.operation} ${i.path}`).join(`
4
- `)}function K(e){let t=Ne(e.rawOutput);if(t!==void 0)return t;let i=ve(e.content);if(i.length>0)return i;return Me(e)}function Ae({block:e,command:t}){let{t:i,Output:a,commandStatus:r}=L(),[o,d]=D(!1),[l,c]=D(!1),u=K(e),s=r===void 0?e.exitCode===void 0?void 0:i("stream.codex.exitCode",{code:e.exitCode}):r(e),m=()=>{navigator.clipboard.writeText([`$ ${t}`,u].filter((x)=>x!==void 0).join(`
5
- `)),d(!0),setTimeout(()=>d(!1),1500)};return n("div",{className:"codex-command-details",children:p("div",{className:"codex-command-card",children:[p("div",{className:"codex-command-line-row",children:[n("span",{className:"codex-command-prompt","aria-hidden":"true",children:"$"}),n("button",{type:"button",className:C("codex-command-line",!l&&"codex-command-line-clamped"),"data-codex-disclosure":"","aria-expanded":l,onClick:()=>c((x)=>!x),children:t}),n("button",{type:"button",className:"codex-command-copy","aria-label":i("actions.copy"),onClick:m,children:o?n(de,{}):n(ce,{})})]}),u!==void 0&&(a===void 0?n("pre",{className:"codex-command-output",children:u}):n(a,{text:u})),s!==void 0&&n("div",{className:"codex-command-footer",children:n("span",{className:"codex-command-status",children:s})})]})})}function k({block:e}){let{t,openLink:i,Patch:a,openImage:r,commandStatus:o,expandToolOutput:d=!1}=L(),l=K(e),c=a===void 0?void 0:e.content.flatMap((g)=>{if(g.type!=="diff")return[];let b=g;return b.patch?.text?[b.patch.text]:[]}).join(`
6
- `),u=we(e.content),s=Le(e.content),[m,x]=E(`tool:${e.id}`,!1),h=P(`tool:${e.id}`,m),y=O(e),v=y.category,f=Y(e,t),S=v==="execute"?T(e,"command"):void 0,N=S!==void 0||R(e)||u.length>0||s.length>0||Boolean(c)||d&&l!==void 0,F=!N&&!w(e.status)?y.filePath:void 0;if(v==="execute"&&!w(e.status)&&e.status!=="completed"){let g=o?.(e);if(g)f={...f,leading:g}}if(v==="read"&&w(e.status))return null;let B=p("span",{className:"codex-activity-label",children:[n(X,{block:e}),n("span",{className:"min-w-0 flex-1 truncate",children:w(e.status)?n("span",{className:"codex-activity-running",children:f.trailing===void 0?f.leading:`${f.leading} ${f.trailing}`}):p(j,{children:[n("span",{className:"codex-activity-leading",children:f.leading}),f.trailing!==void 0&&(F!==void 0?p(j,{children:[" ",n("button",{type:"button",className:"codex-activity-trailing codex-activity-file-link",title:F,onClick:()=>i(F),children:f.trailing})]}):p("span",{className:"codex-activity-trailing",children:[" ",f.trailing]}))]})})]});return p("div",{className:"codex-activity-item",children:[N?p("button",{type:"button",className:"codex-activity-header","data-codex-disclosure":"","aria-label":f.trailing===void 0?f.leading:`${f.leading} ${f.trailing}`,"aria-expanded":m,onClick:()=>x((g)=>!g),children:[B,n(_,{expanded:m})]}):n("div",{className:"codex-activity-header codex-activity-header-static",children:B}),n("div",{className:C("codex-activity-details-grid",m&&"codex-activity-details-grid-open"),children:n("div",{className:"min-h-0 overflow-hidden",children:h&&p(j,{children:[S!==void 0?n(Ae,{block:e,command:S}):a!==void 0&&c?n(a,{patch:c}):l!==void 0&&n("pre",{className:"codex-activity-details",children:l}),u.length>0&&n("div",{className:"codex-activity-media",children:u.map((g)=>{let b=`data:${g.mimeType};base64,${g.data}`,G=n("img",{src:b,className:"max-h-48 max-w-full rounded-lg object-contain",alt:""},`${g.mimeType}:${g.data.slice(0,32)}`);return r===void 0?G:n("button",{type:"button",className:"cursor-pointer",onClick:()=>r(b),children:G},b)})}),s.map((g)=>n("audio",{className:"mt-1 w-full","aria-label":t("stream.codex.audioOutput"),controls:!0,src:`data:${g.mimeType};base64,${g.data}`},`${g.mimeType}:${g.data.slice(0,32)}`))]})})})]})}function ee({block:e}){if(e.type==="tool_use")return n(k,{block:e});if(e.type==="thinking")return n(oe,{block:e});if(e.type==="collab")return n(re,{block:e});return n(te,{block:e})}function te({block:e}){let{t,openSession:i}=L(),a=w(e.status),[r,o]=E(`subagent:${e.id}`,a),d=I(a);A(()=>{if(a)o(!0);if(d.current&&!a)o(!1);d.current=a},[a,o]);let l=`${Ee(e.activity,a,e.name,t)}${ne(e.model,e.reasoningEffort,t)}`,c=e.threadId??"",u=e.blocks.length>0;return p("div",{className:"codex-activity-item",children:[p("button",{type:"button",className:C("codex-activity-header",!u&&"codex-activity-header-static"),"data-codex-disclosure":"","aria-expanded":u?r:void 0,disabled:!u,onClick:()=>o((s)=>!s),children:[p("span",{className:"codex-activity-label",children:[n(Te,{seed:e.threadId??e.id}),n("span",{className:"min-w-0 flex-1 truncate",children:i===void 0||e.threadId===null?a?n("span",{className:"codex-activity-running",children:l}):l:n("span",{role:"link",tabIndex:0,className:C("codex-agent-link",a&&"codex-activity-running"),"aria-label":t("stream.codex.subagentOpen",{name:e.name}),onClick:(s)=>{s.stopPropagation(),i(c,e.name)},onKeyDown:(s)=>{if(s.key!=="Enter"&&s.key!==" ")return;s.preventDefault(),s.stopPropagation(),i(c,e.name)},children:l})})]}),u&&n(_,{expanded:r})]}),n("div",{className:C("codex-activity-details-grid",r&&"codex-activity-details-grid-open"),children:n("div",{className:"min-h-0 overflow-hidden",children:n("div",{className:"codex-subagent-details",children:e.blocks.map((s)=>{if(s.type==="tool_use")return n(k,{block:s},s.id);if(s.type==="thinking")return n(oe,{block:s},M(s));if(s.type==="subagent")return n(te,{block:s},s.id);if(s.type==="collab")return n(re,{block:s},s.id);if(s.type==="text")return n("div",{className:"codex-reasoning-details",children:n(Q,{text:s.text,streaming:!1})},M(s));if(s.type==="plan")return n(ue,{entries:s.entries},M(s));if(s.type==="image")return n("img",{src:`data:${s.source.media_type};base64,${s.source.data}`,className:"max-h-48 max-w-full rounded-lg object-contain",alt:""},M(s));return null})})})})]})}var Ie=8;function be(e){let t=0;for(let i=0;i<e.length;i+=1)t=(t*31+e.charCodeAt(i))%2147483647;return t%Ie}function Te({seed:e}){return n("span",{className:"codex-agent-avatar","data-hue":be(e),"aria-hidden":"true"})}function Ee(e,t,i,a){switch(e){case"started":return a(t?"stream.codex.subagentWorking":"stream.codex.subagentFinished",{name:i});case"interacted":return a("stream.codex.subagentMessaged",{name:i});case"interrupted":return a("stream.codex.subagentInterrupted",{name:i});case"completed":return a("stream.codex.subagentFinished",{name:i})}}var _e=new Set(["none","minimal","low","medium","high","xhigh","max","ultra","persistent"]);function ne(e,t,i){if(e===null)return"";if(t===null)return` · ${q(e)}`;let a=_e.has(t)?i(`stream.codex.reasoningEffort.${t}`):t;return` · ${q(e)} · ${a}`}var Se={spawnAgent:"spawn",sendInput:"message",sendMessage:"message",followupTask:"message",interruptAgent:"interrupt",listAgents:"list",resumeAgent:"resume",closeAgent:"close"};function ae(e){switch(e){case"pending":case"in_progress":return"inProgress";case"completed":return"completed";case"failed":return"failed";case"cancelled":case"interrupted":return"interrupted";default:throw Error(`Unknown ACP tool status: ${e}`)}}function H(e,t,i){if(e.tool==="wait")throw Error("Codex does not present wait calls");let a=ae(e.status);if(a==="interrupted")return i("stream.codex.collab.interrupted");return i(`stream.codex.collab.${t}.${Se[e.tool]}.${a}`)}function Fe(e){return e.agents.filter((t)=>t.nickname!==null)}function ie(e,t){let i=e.agents.length>0?e.agents.length:1;return`${H(e,"header",t)}${t("stream.codex.collab.agentCount",{count:i})}`}var V="\x01";function Z(e,t,i,a){let r=Object.fromEntries(Object.keys(a).map((o)=>[o,`${V}${o}${V}`]));return e(t,{...i,...r}).split(new RegExp(`${V}(\\w+)${V}`,"u")).map((o,d)=>n(le,{children:d%2===1?a[o]:o},`${d}:${o}`))}function Be({agent:e,showModel:t}){let{t:i,openSession:a}=L(),r=e.nickname??"",o=a===void 0?n("span",{className:"font-medium",children:r}):n("button",{type:"button",className:"codex-agent-link font-medium","aria-label":i("stream.codex.subagentOpen",{name:r}),onClick:()=>a(e.threadId,r),children:r});return p("span",{children:[o,e.role!==null&&` (${e.role})`,t&&ne(e.model,e.reasoningEffort,i)]})}function J({prompt:e}){return n("span",{className:"codex-collab-prompt",title:e,children:e})}function De(e,t){let i=e.prompt?.trim()?e.prompt:null,a=ae(e.status),r=e.tool==="spawnAgent"&&a==="completed"&&i!==null,o=(e.tool==="sendInput"||e.tool==="sendMessage"||e.tool==="followupTask")&&i!==null,d=Fe(e),l=[];if(d.length===0)l.push({key:"generic",node:H(e,"row",t)});for(let c of d){let u=n(Be,{agent:c,showModel:e.tool==="spawnAgent"});if(r)l.push({key:c.threadId,node:n("span",{className:"codex-collab-line",children:Z(t,"stream.codex.collab.createdWithInstructions",{},{agent:u,instructions:n(J,{prompt:i})})})});else if(o)l.push({key:c.threadId,node:n("span",{className:"codex-collab-line",children:Z(t,"stream.codex.collab.messagedWithPrompt",{action:a==="interrupted"?t("stream.codex.collab.interrupted"):t(`stream.codex.collab.messaged.${a}`)},{agent:u,prompt:n(J,{prompt:i})})})});else{let m=e.tool!=="closeAgent"&&e.tool!=="resumeAgent"&&c.state!==null&&c.state!==null?c.state.message?.trim()?t("stream.codex.collab.stateWithMessage",{state:t(`stream.codex.collab.state.${c.state.status}`),message:c.state.message}):t("stream.codex.collab.stateOnly",{state:t(`stream.codex.collab.state.${c.state.status}`)}):"";l.push({key:c.threadId,node:Z(t,"stream.codex.collab.agentRow",{action:H(e,"row",t),state:m},{agent:u})})}}if(!r&&!o&&i!==null)l.push({key:"input",node:Z(t,"stream.codex.collab.input",{},{prompt:n("span",{className:"codex-collab-input",children:i})})});return l}function re({block:e}){let{t}=L(),[i,a]=E(`collab:${e.id}`,!1);if(e.tool==="wait")return null;let r=w(e.status),o=ie(e,t);return p("div",{className:"codex-activity-item",children:[p("button",{type:"button",className:"codex-activity-header","data-codex-disclosure":"","aria-expanded":i,onClick:()=>a((d)=>!d),children:[p("span",{className:"codex-activity-label",children:[n(se,{className:"size-4 shrink-0","aria-hidden":"true"}),n("span",{className:"min-w-0 flex-1 truncate",children:r?n("span",{className:"codex-activity-running",children:o}):o})]}),n(_,{expanded:i})]}),n("div",{className:C("codex-activity-details-grid",i&&"codex-activity-details-grid-open"),children:n("div",{className:"min-h-0 overflow-hidden",children:n("div",{className:"codex-subagent-details",children:De(e,t).map((d)=>n("div",{className:"codex-collab-row",children:d.node},d.key))})})})]})}function oe({block:e}){let{t,i18n:i}=L(),a=Boolean(e.isComplete),[r,o]=E(`thinking:${M(e)}:${a?"complete":"streaming"}`,!a),d=I(a),l=I(null);A(()=>{if(!a)o(!0);if(!d.current&&a)o(!1);d.current=a},[a,o]);let c=e.thinking.trim().length>0;A(()=>{if(a||!c)return;let m=l.current;if(m===null)throw Error("Thinking details are not mounted");let x=new ResizeObserver(()=>{m.scrollTop=m.scrollHeight}),h=null,y=()=>{let f=m.firstElementChild;if(f===h)return;if(h!==null)x.unobserve(h);if(h=f,h!==null)x.observe(h)},v=new MutationObserver(y);return v.observe(m,{childList:!0}),y(),()=>{v.disconnect(),x.disconnect()}},[c,a]);let u=a?e.durationMs!==void 0?t("stream.codex.thoughtFor",{duration:W(e.durationMs,i.language)}):t("stream.codex.thought"):t("message.thinking"),s=e.thinking.trimStart().replace(/^\*\*[^\n]*?\*\*\s*/,"");return p("div",{className:"codex-activity-item",children:[p("button",{type:"button",className:C("codex-activity-header",!c&&"codex-activity-header-static"),"data-codex-disclosure":"","aria-expanded":c?r:void 0,disabled:!c,onClick:()=>o((m)=>!m),children:[n("span",{className:"codex-activity-label",children:n("span",{className:"codex-reasoning-label min-w-0 flex-1 truncate",children:a?u:n("span",{className:"codex-activity-running",children:u})})}),c&&n(_,{expanded:r})]}),n("div",{className:C("codex-activity-details-grid",r&&"codex-activity-details-grid-open"),children:n("div",{className:"min-h-0 overflow-hidden",children:c&&n("div",{ref:l,className:"codex-reasoning-details",role:"region","aria-label":u,"aria-hidden":!r,tabIndex:0,inert:!r,children:n(Q,{text:s,streaming:!a})})})})]})}function Oe(e){if(R(e))return"mcp";let t=O(e).category;return t==="think"||t==="switch_mode"?"other":t}function Ve(e,t,i,a){return a(`stream.codex.summary.${e}.${i?"leading":"following"}`,{count:t})}function Ze(e,t,i){let a=new Map;for(let o of e){let d=Oe(o);a.set(d,(a.get(d)??0)+1)}let r=Array.from(a,([o,d],l)=>Ve(o,d,l===0,t));if(i.startsWith("zh"))return r.join("");return new Intl.ListFormat(i,{style:"long",type:"conjunction"}).format(r)}function Ke({stateKey:e,durationMs:t,durationKind:i="work",active:a,startedAt:r,providerId:o,providerIcon:d,children:l}){let{t:c,i18n:u}=L(),[s,m]=E(`work:${e}`,a),x=P(`work:${e}`,s||a),h=I(a),y=I(null),[v,f]=D(0);A(()=>{if(a)m(!0);if(h.current&&!a)m(!1);h.current=a},[a,m]),A(()=>{if(!a||t!==void 0){y.current=null;return}y.current=r??Date.now();let N=()=>{let B=y.current;if(B===null)throw Error("Codex work section is ticking without a start time");f(Date.now()-B)};N();let F=window.setInterval(N,1000);return()=>window.clearInterval(F)},[a,r,t]);let S=t!==void 0?c(i==="total"?"stream.codex.totalDuration":"stream.codex.workedFor",{duration:W(t,u.language)}):a&&v>=1000?c("stream.codex.workedFor",{duration:W(v,u.language)}):c("stream.codex.worked");return p("section",{className:"codex-work-section",children:[p("button",{type:"button",className:"codex-work-trigger","data-codex-disclosure":"","aria-expanded":s,onClick:()=>m((N)=>!N),children:[o!==void 0&&n("span",{className:"codex-work-provider-icon","data-testid":"codex-work-provider-icon","data-provider-id":o,"aria-hidden":"true",children:d}),n("span",{children:S}),n(_,{expanded:s,className:"codex-work-chevron"})]}),n("div",{className:"codex-work-separator","aria-hidden":"true"}),n("div",{className:C("codex-work-grid",s&&"codex-work-grid-open"),children:n("div",{className:"min-h-0 overflow-hidden",children:n("div",{className:"codex-work-body",children:x&&l})})})]})}function je(e,t){if(e.type==="tool_use")return ye(e,t);if(e.type==="thinking")return t("message.thinking");if(e.type==="collab")return ie(e,t);return t("stream.codex.subagentWorking",{name:e.name})}function We(e){if(e.type==="thinking")return!e.isComplete;if(e.type==="tool_use"||e.type==="subagent"||e.type==="collab")return w(e.status);return!1}function He(e,t=1000){let[i,a]=D(e),r=I(Date.now());return A(()=>{if(e===i)return;let o=Date.now(),d=Math.max(0,r.current+t-o);if(d===0){r.current=o,a(e);return}let l=window.setTimeout(()=>{r.current=Date.now(),a(e)},d);return()=>window.clearTimeout(l)},[i,t,e]),i}function Pe({blocks:e}){let{t,i18n:i}=L(),a=e.some(We),r=e.map(M).join(":"),[o,d]=E(`group:${r}`,a),l=P(`group:${r}`,o||a),c=I(a);A(()=>{if(a)d(!0);if(c.current&&!a)d(!1);c.current=a},[a,d]);let u=e.at(-1);if(u===void 0)throw Error("CodexActivityGroup requires at least one activity block");let s=e.filter((x)=>x.type==="tool_use"),m=He(a?je(u,t):Ze(s,t,i.language));return p("div",{className:"codex-activity-group",children:[p("button",{type:"button",className:"codex-activity-group-trigger","aria-expanded":o,onClick:()=>d((x)=>!x),children:[p("span",{className:"codex-activity-label",children:[n(X,{block:e[0]}),n("span",{className:"truncate",children:a?n("span",{className:"codex-activity-running",children:m}):m})]}),n(_,{expanded:o})]}),n("div",{className:C("codex-activity-group-grid",o&&"codex-activity-group-grid-open"),children:n("div",{className:"min-h-0 overflow-hidden",children:n("div",{className:"codex-activity-group-body",children:l&&e.map((x)=>n(ee,{block:x},M(x)))})})})]})}function ke({blocks:e}){if(e.length===0)throw Error("CodexActivityGroup requires at least one activity block");if(e.length===1)return n(ee,{block:e[0]});return n(Pe,{blocks:e})}export{ke as CodexActivityGroup,Ke as CodexWorkSection};
1
+ import{jsx as n,jsxs as p,Fragment as j}from"react/jsx-runtime";import{cn as C}from"cn";import{BotIcon as de,CheckIcon as ce,CopyIcon as le}from"lucide-react";import{Fragment as ue,useEffect as A,useRef as I,useState as D}from"react";import{ActivityMarkdown as X,useActivityHost as L}from"../activity-host.js";import{formatModelName as q}from"../lib/model-name.js";import{describeToolUse as O}from"../lib/stream-style.js";import{useCodexDisclosureState as E}from"./disclosure-state.js";import{CodexPlan as me}from"./plan.js";function P(e,t){let[i,a]=D(()=>({key:e,mounted:t})),r=t||i.key===e&&i.mounted;if(i.key!==e||i.mounted!==r)a({key:e,mounted:r});return r}var z=new WeakMap,U=1;function M(e){if(e.type==="tool_use"||e.type==="subagent"||e.type==="collab")return`${e.type}:${e.id}`;if(e.type==="thinking"&&e.id!==void 0)return`thinking:${e.id}`;let t=z.get(e);if(t!==void 0)return`${e.type}:${t}`;let i=U;return U+=1,z.set(e,i),`${e.type}:${i}`}function w(e){switch(e){case"pending":case"in_progress":return!0;case"completed":case"failed":case"cancelled":case"interrupted":return!1;default:throw Error(`Unknown ACP tool status: ${e}`)}}function W(e,t){let i=Math.max(0,Math.round(e/1000)),a=Math.floor(i/3600),r=Math.floor(i%3600/60),o=i%60;if(o>=60)r+=Math.floor(o/60),o%=60;if(r>=60)a+=Math.floor(r/60),r%=60;let d=Intl.DurationFormat;if(d)try{return new d(t,{style:"narrow"}).format({hours:a,minutes:r,seconds:a>0?0:o})}catch{}if(a>0)return r>0?`${a}h ${r}m`:`${a}h`;if(r>0)return o>0?`${r}m ${o}s`:`${r}m`;return`${o}s`}var pe="M7.52925 3.7793C7.75652 3.55203 8.10803 3.52383 8.36616 3.69434L8.47065 3.7793L14.2207 9.5293C14.4804 9.789 14.4804 10.211 14.2207 10.4707L8.47065 16.2207C8.21095 16.4804 7.78895 16.4804 7.52925 16.2207C7.26955 15.961 7.26955 15.539 7.52925 15.2793L12.8085 10L7.52925 4.7207L7.44429 4.61621C7.27378 4.35808 7.30198 4.00657 7.52925 3.7793Z";function _({expanded:e,className:t}){return n("svg",{className:C("codex-activity-disclosure",e&&"codex-activity-disclosure-expanded",t),viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:n("path",{d:pe})})}function fe(){return n("svg",{className:"codex-activity-icon",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:n("path",{d:"M16.3965 5.01128C16.3963 4.93399 16.3489 4.87691 16.293 4.85406L16.2354 4.84332C13.9306 4.91764 12.5622 5.32101 10.665 6.34722V16.3716C11.3851 15.9994 12.0688 15.7115 12.7861 15.5015C13.8286 15.1965 14.9113 15.0633 16.2402 15.0435L16.2979 15.0308C16.353 15.0063 16.3965 14.9483 16.3965 14.8755V5.01128ZM3.54492 14.8765C3.54492 14.9725 3.62159 15.0422 3.70117 15.0435L4.19629 15.0562C5.94062 15.1247 7.26036 15.4201 8.65918 16.0484C8.05544 15.1706 7.14706 14.436 6.17871 14.1109V14.1099C5.56757 13.9045 5.16816 13.3314 5.16797 12.6988V4.98882C4.86679 4.93786 4.60268 4.8999 4.28223 4.87457L3.72754 4.84429C3.62093 4.84079 3.54505 4.92417 3.54492 5.01226V14.8765ZM17.7266 14.8755C17.7266 15.6314 17.1607 16.2751 16.4121 16.3628L16.2598 16.3736C15.0122 16.3922 14.0555 16.5159 13.1602 16.7779C12.2629 17.0404 11.3966 17.4508 10.3369 18.0738C10.129 18.1959 9.87099 18.1958 9.66309 18.0738C7.71455 16.9283 6.31974 16.4689 4.12988 16.3853L3.68164 16.3736C2.85966 16.3614 2.21484 15.6838 2.21484 14.8765V5.01226C2.21497 4.15391 2.93263 3.4871 3.77246 3.51519L4.39844 3.54937C4.67996 3.57191 4.92258 3.60421 5.16797 3.64214V2.51031C5.16797 1.44939 6.29018 0.645615 7.31055 1.15679L7.31152 1.15582C8.78675 1.89511 10.0656 3.33006 10.5352 4.91461C12.3595 3.98907 13.8688 3.58817 16.1924 3.51324L16.3506 3.51714C17.1285 3.5741 17.7264 4.23496 17.7266 5.01128V14.8755ZM6.49805 12.6988C6.49824 12.7723 6.5442 12.8296 6.60254 12.8492L6.96289 12.9859C7.85245 13.3586 8.68125 13.9846 9.33496 14.7496V5.5816C9.08794 4.37762 8.13648 3.1566 6.95801 2.47613L6.71582 2.34527C6.67779 2.32617 6.6337 2.32502 6.58301 2.35796C6.52946 2.39279 6.49805 2.44863 6.49805 2.51031V12.6988Z"})})}function xe(){return n("svg",{className:"codex-activity-icon",viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:n("path",{d:"M7.33057 1.98535C10.2484 1.98535 12.6136 4.3508 12.6138 7.26855C12.6138 8.58031 12.1346 9.77942 11.3433 10.7031L13.9897 13.3496C14.1655 13.5253 14.1655 13.8106 13.9897 13.9863C13.814 14.1621 13.5288 14.1621 13.353 13.9863L10.7017 11.335C9.78678 12.0942 8.61243 12.5518 7.33057 12.5518C4.41281 12.5516 2.04736 10.1864 2.04736 7.26855C2.04754 4.35091 4.41292 1.98553 7.33057 1.98535ZM7.33057 2.88574C4.90998 2.88592 2.94793 4.84796 2.94775 7.26855C2.94775 9.68929 4.90987 11.6522 7.33057 11.6523C9.75141 11.6523 11.7144 9.6894 11.7144 7.26855C11.7142 4.84786 9.75131 2.88574 7.33057 2.88574Z"})})}function ge(){return p("svg",{className:"codex-activity-icon",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:[n("path",{d:"M6.19629 7.86231C6.42357 7.63534 6.7752 7.60692 7.0332 7.77734L7.1377 7.86231L8.80371 9.5293C9.06329 9.78889 9.06307 10.21 8.80371 10.4697L7.1377 12.1367C6.878 12.3964 6.45599 12.3964 6.19629 12.1367C5.93686 11.8771 5.93697 11.456 6.19629 11.1963L7.39258 9.99902L6.19629 8.80371L6.11133 8.69922C5.94087 8.4411 5.96904 8.08955 6.19629 7.86231Z"}),n("path",{d:"M13.4668 11.0156C13.7699 11.0776 13.998 11.3456 13.998 11.667C13.9979 11.9883 13.7698 12.2564 13.4668 12.3184L13.333 12.332H10.833C10.466 12.3319 10.1682 12.034 10.168 11.667C10.168 11.2998 10.4659 11.0021 10.833 11.002H13.333L13.4668 11.0156Z"}),n("path",{d:"M12.6602 2.66504C13.3492 2.66504 13.9062 2.66439 14.3564 2.70117C14.8142 2.73859 15.2201 2.81796 15.5967 3.00977C16.1922 3.31321 16.677 3.79805 16.9805 4.39356C17.1722 4.77014 17.2517 5.17604 17.2891 5.63379C17.3258 6.08402 17.3252 6.64102 17.3252 7.33008V12.6602C17.3252 13.3492 17.3258 13.9062 17.2891 14.3564C17.2516 14.8142 17.1723 15.2201 16.9805 15.5967C16.677 16.1922 16.1922 16.677 15.5967 16.9805C15.2201 17.1723 14.8142 17.2516 14.3564 17.2891C13.9062 17.3258 13.3492 17.3252 12.6602 17.3252H7.33008C6.64102 17.3252 6.08402 17.3258 5.63379 17.2891C5.17604 17.2517 4.77014 17.1722 4.39356 16.9805C3.79805 16.677 3.31321 16.1922 3.00977 15.5967C2.81796 15.2201 2.73859 14.8142 2.70117 14.3564C2.66439 13.9062 2.66504 13.3492 2.66504 12.6602V7.33008C2.66504 6.64101 2.66439 6.08402 2.70117 5.63379C2.73858 5.17601 2.81797 4.77016 3.00977 4.39356C3.31321 3.79802 3.79802 3.31321 4.39356 3.00977C4.77016 2.81797 5.17601 2.73858 5.63379 2.70117C6.08402 2.66439 6.64101 2.66504 7.33008 2.66504H12.6602ZM7.33008 3.99512C6.61907 3.99512 6.1257 3.99601 5.74219 4.02734C5.3665 4.05804 5.15508 4.11481 4.99707 4.19531C4.65183 4.37124 4.37124 4.65183 4.19531 4.99707C4.11481 5.15508 4.05805 5.3665 4.02734 5.74219C3.99601 6.1257 3.99512 6.61908 3.99512 7.33008V12.6602C3.99512 13.3711 3.99601 13.8646 4.02734 14.248C4.05805 14.6237 4.11481 14.8352 4.19531 14.9932C4.37124 15.3384 4.65186 15.619 4.99707 15.7949C5.15507 15.8754 5.36654 15.9322 5.74219 15.9629C6.1257 15.9942 6.61908 15.9951 7.33008 15.9951H12.6602C13.3711 15.9951 13.8646 15.9942 14.248 15.9629C14.6237 15.9322 14.8352 15.8754 14.9932 15.7949C15.3384 15.619 15.619 15.3384 15.7949 14.9932C15.8754 14.8352 15.9322 14.6237 15.9629 14.248C15.9942 13.8646 15.9951 13.3711 15.9951 12.6602V7.33008C15.9951 6.61908 15.9942 6.1257 15.9629 5.74219C15.9322 5.36654 15.8754 5.15507 15.7949 4.99707C15.619 4.65186 15.3384 4.37124 14.9932 4.19531C14.8352 4.11481 14.6237 4.05805 14.248 4.02734C13.8646 3.99601 13.3711 3.99512 12.6602 3.99512H7.33008Z"})]})}function he(){return n("svg",{className:"codex-activity-icon",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:n("path",{d:"M11.3312 4.20472C12.7488 2.92391 14.9377 2.96644 16.3039 4.33265L16.4318 4.46742C17.6713 5.8393 17.6713 7.93343 16.4318 9.30531L16.3039 9.44007L10.0119 15.7311C9.68839 16.0546 9.45384 16.2917 9.22185 16.4821L8.98748 16.6588C8.78233 16.799 8.56429 16.9196 8.33709 17.0192L8.10759 17.1119C7.92582 17.1785 7.73843 17.2266 7.52166 17.2711L6.75701 17.4069L4.36345 17.8053C4.22059 17.8291 4.06914 17.8552 3.9406 17.8649C3.84183 17.8723 3.70833 17.875 3.56267 17.8395L3.41423 17.7907C3.19121 17.695 3.00747 17.5271 2.89177 17.316L2.84588 17.2223C2.75958 17.0209 2.76174 16.8276 2.77166 16.6959C2.78136 16.5674 2.80742 16.4159 2.83123 16.2731L3.22966 13.8795L3.36443 13.1149C3.40899 12.898 3.45795 12.7108 3.52459 12.5289L3.61736 12.2985C3.71691 12.0715 3.83772 11.854 3.97771 11.6491L4.15349 11.4147C4.34392 11.1825 4.58171 10.9484 4.90545 10.6246L11.1965 4.33265L11.3312 4.20472ZM5.84588 11.5651C5.49671 11.9142 5.31258 12.0998 5.1867 12.2526L5.07537 12.3991C4.98194 12.5358 4.90157 12.6812 4.83513 12.8327L4.77361 12.9869C4.73328 13.0971 4.70248 13.2125 4.66814 13.3815L4.54119 14.0983L4.14275 16.4918L4.14177 16.4938H4.1447L6.53826 16.0944L7.25505 15.9684C7.42406 15.9341 7.53946 15.9033 7.64959 15.8629L7.80291 15.8014C7.95461 15.7349 8.09953 15.6538 8.2365 15.5602L8.38396 15.4498C8.53674 15.3239 8.72231 15.1398 9.07146 14.7907L14.0588 9.80238L10.8332 6.57679L5.84588 11.5651ZM15.3635 5.27308C14.5281 4.43776 13.2058 4.38573 12.3097 5.11683L12.1369 5.27308L11.7736 5.63636L15.0002 8.86195L15.3635 8.49964L15.5197 8.32581C16.2015 7.48961 16.2015 6.28311 15.5197 5.44691L15.3635 5.27308Z"})})}function Ce(){return n("svg",{className:"codex-activity-icon",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:n("path",{d:"M16.8347 7.91699C16.8347 7.76279 16.8266 7.61021 16.8123 7.45996L15.4705 8.80371C14.2903 9.98388 12.3762 9.98388 11.1961 8.80371C10.016 7.62352 10.0159 5.70942 11.1961 4.5293L12.5378 3.18652C12.3885 3.17238 12.237 3.16505 12.0837 3.16504C9.45947 3.16504 7.33179 5.29272 7.33179 7.91699C7.33184 8.56608 7.46162 9.18329 7.69605 9.74512C7.79981 9.9939 7.74311 10.2811 7.5525 10.4717L3.59547 14.4287C3.0498 14.9744 3.04991 15.8586 3.59547 16.4043L3.70191 16.501C4.25076 16.9483 5.05957 16.9158 5.57105 16.4043L9.52906 12.4473L9.60426 12.3828C9.79018 12.2455 10.0369 12.2131 10.2546 12.3037C10.8166 12.5382 11.4345 12.668 12.0837 12.668C14.7078 12.6678 16.8345 10.541 16.8347 7.91699ZM18.1648 7.91699C18.1646 11.2755 15.4423 13.9979 12.0837 13.998C11.4151 13.998 10.7708 13.8886 10.1677 13.6885L6.51246 17.3457C5.51389 18.3443 3.93332 18.406 2.86207 17.5322L2.65504 17.3457C1.58992 16.2806 1.58992 14.5534 2.65504 13.4883L6.31031 9.83203C6.1104 9.22921 6.00175 8.58526 6.00172 7.91699C6.00172 4.55818 8.72494 1.83496 12.0837 1.83496C12.7838 1.835 13.458 1.95316 14.0857 2.17188L14.1638 2.20508C14.3404 2.29325 14.4697 2.45713 14.5144 2.65234C14.5653 2.87533 14.4984 3.10876 14.3367 3.27051L12.1375 5.4707C11.4767 6.13148 11.4767 7.20251 12.1375 7.86328C12.7983 8.52373 13.8694 8.52395 14.53 7.86328L16.7293 5.66309L16.7937 5.60742C16.9499 5.48687 17.1532 5.44067 17.3484 5.48535C17.5714 5.53648 17.7526 5.69898 17.8279 5.91504C18.0466 6.54272 18.1648 7.21689 18.1648 7.91699Z"})})}function Y({block:e}){if(e.type!=="tool_use")return null;let t=O(e).category;if(t==="read")return n(fe,{});if(t==="search"||t==="fetch")return n(xe,{});if(t==="execute")return n(ge,{});if(t==="edit")return n(he,{});return n(Ce,{})}function T(e,t){let i=e.rawInput[t];return typeof i==="string"&&i.length>0?i:void 0}function ye(e){return O(e).target}function R(e){return e.name.startsWith("mcp__")||e.name.startsWith("mcp_")}function K(e,t){let{category:i}=O(e),a=ye(e),r=w(e.status);if(R(e))return{leading:e.title};if(i==="execute"){let o=T(e,"command")?.split(`
2
+ `)[0]??a;return o?{leading:t(r?"stream.codex.running":"stream.codex.ran"),trailing:o}:{leading:t(r?"stream.codex.runningCommand":"stream.codex.ranCommandGeneric")}}if(i==="search"){let o=T(e,"pattern")??T(e,"query")??a;return o?{leading:t(r?"stream.codex.searching":"stream.codex.searched"),trailing:t("stream.codex.forDetail",{detail:o})}:{leading:t(r?"stream.codex.searchingFiles":"stream.codex.searchedFiles")}}if(i==="fetch"){let o=T(e,"query")??T(e,"url")??a;return o?{leading:t(r?"stream.codex.searchingWeb":"stream.codex.searchedWeb"),trailing:t("stream.codex.forDetail",{detail:o})}:{leading:t(r?"stream.codex.searchingWeb":"stream.codex.searchedWeb")}}if(i==="read")return a?{leading:t("stream.codex.readLabel"),trailing:a}:{leading:t("stream.codex.readFiles")};if(i==="edit")return a?{leading:t(r?"stream.codex.editingLabel":"stream.codex.editedLabel"),trailing:a}:{leading:t(r?"stream.codex.editingFiles":"stream.codex.editedFiles")};if(i==="delete")return a?{leading:t(r?"stream.codex.deletingLabel":"stream.codex.deletedLabel"),trailing:a}:{leading:t(r?"stream.codex.deletingFiles":"stream.codex.deletedFiles")};if(i==="move")return a?{leading:t(r?"stream.codex.movingLabel":"stream.codex.movedLabel"),trailing:a}:{leading:t(r?"stream.codex.movingFiles":"stream.codex.movedFiles")};return{leading:e.title}}function ve(e,t){let i=K(e,t);return i.trailing===void 0?i.leading:`${i.leading} ${i.trailing}`}function we(e){return e.map((t)=>{if(t.type!=="content")return"";let i=t.content;return i.type==="text"?i.text:""}).filter(Boolean).join(`
3
+ `).trim()}function Le(e){return e.flatMap((t)=>{if(t.type!=="content")return[];let i=t.content;return i.type==="image"?[{data:i.data,mimeType:i.mimeType}]:[]})}function Ne(e){return e.flatMap((t)=>{if(t.type!=="content")return[];let i=t.content;return i.type==="audio"?[{data:i.data,mimeType:i.mimeType}]:[]})}function $e(e){if(typeof e==="string"&&e.length>0)return e;return}function Me(e){return e.type==="diff"}function Ae(e){let t=e.content.find(Me);if(t===void 0)return;return t.changes.map((i)=>`${i.operation} ${i.path}`).join(`
4
+ `)}function k(e){let t=$e(e.rawOutput);if(t!==void 0)return t;let i=we(e.content);if(i.length>0)return i;return Ae(e)}function Ie({block:e,command:t}){let{t:i,Output:a,commandStatus:r}=L(),[o,d]=D(!1),[l,c]=D(!1),u=k(e),s=r===void 0?e.exitCode===void 0?void 0:i("stream.codex.exitCode",{code:e.exitCode}):r(e),m=()=>{navigator.clipboard.writeText([`$ ${t}`,u].filter((x)=>x!==void 0).join(`
5
+ `)),d(!0),setTimeout(()=>d(!1),1500)};return n("div",{className:"codex-command-details",children:p("div",{className:"codex-command-card",children:[p("div",{className:"codex-command-line-row",children:[n("span",{className:"codex-command-prompt","aria-hidden":"true",children:"$"}),n("button",{type:"button",className:C("codex-command-line",!l&&"codex-command-line-clamped"),"data-codex-disclosure":"","aria-expanded":l,onClick:()=>c((x)=>!x),children:t}),n("button",{type:"button",className:"codex-command-copy","aria-label":i("actions.copy"),onClick:m,children:o?n(ce,{}):n(le,{})})]}),u!==void 0&&(a===void 0?n("pre",{className:"codex-command-output",children:u}):n(a,{text:u})),s!==void 0&&n("div",{className:"codex-command-footer",children:n("span",{className:"codex-command-status",children:s})})]})})}function ee({block:e}){let{t,openLink:i,Patch:a,openImage:r,commandStatus:o,expandToolOutput:d=!1}=L(),l=k(e),c=a===void 0?void 0:e.content.flatMap((g)=>{if(g.type!=="diff")return[];let b=g;return b.patch?.text?[b.patch.text]:[]}).join(`
6
+ `),u=Le(e.content),s=Ne(e.content),[m,x]=E(`tool:${e.id}`,!1),h=P(`tool:${e.id}`,m),y=O(e),v=y.category,f=K(e,t),S=v==="execute"?T(e,"command"):void 0,N=S!==void 0||R(e)||u.length>0||s.length>0||Boolean(c)||d&&l!==void 0,F=!N&&!w(e.status)?y.filePath:void 0;if(v==="execute"&&!w(e.status)&&e.status!=="completed"){let g=o?.(e);if(g)f={...f,leading:g}}if(v==="read"&&w(e.status))return null;let B=p("span",{className:"codex-activity-label",children:[n(Y,{block:e}),n("span",{className:"min-w-0 flex-1 truncate",children:w(e.status)?n("span",{className:"codex-activity-running",children:f.trailing===void 0?f.leading:`${f.leading} ${f.trailing}`}):p(j,{children:[n("span",{className:"codex-activity-leading",children:f.leading}),f.trailing!==void 0&&(F!==void 0?p(j,{children:[" ",n("button",{type:"button",className:"codex-activity-trailing codex-activity-file-link",title:F,onClick:()=>i(F),children:f.trailing})]}):p("span",{className:"codex-activity-trailing",children:[" ",f.trailing]}))]})})]});return p("div",{className:"codex-activity-item",children:[N?p("button",{type:"button",className:"codex-activity-header","data-codex-disclosure":"","aria-label":f.trailing===void 0?f.leading:`${f.leading} ${f.trailing}`,"aria-expanded":m,onClick:()=>x((g)=>!g),children:[B,n(_,{expanded:m})]}):n("div",{className:"codex-activity-header codex-activity-header-static",children:B}),n("div",{className:C("codex-activity-details-grid",m&&"codex-activity-details-grid-open"),children:n("div",{className:"min-h-0 overflow-hidden",children:h&&p(j,{children:[S!==void 0?n(Ie,{block:e,command:S}):a!==void 0&&c?n(a,{patch:c}):l!==void 0&&n("pre",{className:"codex-activity-details",children:l}),u.length>0&&n("div",{className:"codex-activity-media",children:u.map((g)=>{let b=`data:${g.mimeType};base64,${g.data}`,G=n("img",{src:b,className:"max-h-48 max-w-full rounded-lg object-contain",alt:""},`${g.mimeType}:${g.data.slice(0,32)}`);return r===void 0?G:n("button",{type:"button",className:"cursor-pointer",onClick:()=>r(b),children:G},b)})}),s.map((g)=>n("audio",{className:"mt-1 w-full","aria-label":t("stream.codex.audioOutput"),controls:!0,src:`data:${g.mimeType};base64,${g.data}`},`${g.mimeType}:${g.data.slice(0,32)}`))]})})})]})}function te({block:e}){if(e.type==="tool_use")return n(ee,{block:e});if(e.type==="thinking")return n(se,{block:e});if(e.type==="collab")return n(oe,{block:e});return n(ne,{block:e})}function ne({block:e}){let{t,openSession:i}=L(),a=w(e.status),[r,o]=E(`subagent:${e.id}`,a),d=I(a);A(()=>{if(a)o(!0);if(d.current&&!a)o(!1);d.current=a},[a,o]);let l=`${_e(e.activity,a,e.name,t)}${ae(e.model,e.reasoningEffort,t)}`,c=e.threadId??"",u=e.blocks.length>0;return p("div",{className:"codex-activity-item",children:[p("button",{type:"button",className:C("codex-activity-header",!u&&"codex-activity-header-static"),"data-codex-disclosure":"","aria-expanded":u?r:void 0,disabled:!u,onClick:()=>o((s)=>!s),children:[p("span",{className:"codex-activity-label",children:[n(Ee,{seed:e.threadId??e.id}),n("span",{className:"min-w-0 flex-1 truncate",children:i===void 0||e.threadId===null?a?n("span",{className:"codex-activity-running",children:l}):l:n("span",{role:"link",tabIndex:0,className:C("codex-agent-link",a&&"codex-activity-running"),"aria-label":t("stream.codex.subagentOpen",{name:e.name}),onClick:(s)=>{s.stopPropagation(),i(c,e.name)},onKeyDown:(s)=>{if(s.key!=="Enter"&&s.key!==" ")return;s.preventDefault(),s.stopPropagation(),i(c,e.name)},children:l})})]}),u&&n(_,{expanded:r})]}),n("div",{className:C("codex-activity-details-grid",r&&"codex-activity-details-grid-open"),children:n("div",{className:"min-h-0 overflow-hidden",children:n("div",{className:"codex-subagent-details",children:e.blocks.map((s)=>{if(s.type==="tool_use")return n(ee,{block:s},s.id);if(s.type==="thinking")return n(se,{block:s},M(s));if(s.type==="subagent")return n(ne,{block:s},s.id);if(s.type==="collab")return n(oe,{block:s},s.id);if(s.type==="text")return n("div",{className:"codex-reasoning-details",children:n(X,{text:s.text,streaming:!1})},M(s));if(s.type==="plan")return n(me,{entries:s.entries},M(s));if(s.type==="image")return n("img",{src:`data:${s.source.media_type};base64,${s.source.data}`,className:"max-h-48 max-w-full rounded-lg object-contain",alt:""},M(s));return null})})})})]})}var be=8;function Te(e){let t=0;for(let i=0;i<e.length;i+=1)t=(t*31+e.charCodeAt(i))%2147483647;return t%be}function Ee({seed:e}){return n("span",{className:"codex-agent-avatar","data-hue":Te(e),"aria-hidden":"true"})}function _e(e,t,i,a){switch(e){case"started":return a(t?"stream.codex.subagentWorking":"stream.codex.subagentFinished",{name:i});case"interacted":return a("stream.codex.subagentMessaged",{name:i});case"interrupted":return a("stream.codex.subagentInterrupted",{name:i});case"completed":return a("stream.codex.subagentFinished",{name:i})}}var Se=new Set(["none","minimal","low","medium","high","xhigh","max","ultra","persistent"]);function ae(e,t,i){if(e===null)return"";if(t===null)return` · ${q(e)}`;let a=Se.has(t)?i(`stream.codex.reasoningEffort.${t}`):t;return` · ${q(e)} · ${a}`}var Fe={spawnAgent:"spawn",sendInput:"message",sendMessage:"message",followupTask:"message",interruptAgent:"interrupt",listAgents:"list",resumeAgent:"resume",closeAgent:"close"};function ie(e){switch(e){case"pending":case"in_progress":return"inProgress";case"completed":return"completed";case"failed":return"failed";case"cancelled":case"interrupted":return"interrupted";default:throw Error(`Unknown ACP tool status: ${e}`)}}function H(e,t,i){if(e.tool==="wait")throw Error("Codex does not present wait calls");let a=ie(e.status);if(a==="interrupted")return i("stream.codex.collab.interrupted");return i(`stream.codex.collab.${t}.${Fe[e.tool]}.${a}`)}function Be(e){return e.agents.filter((t)=>t.nickname!==null)}function re(e,t){let i=e.agents.length>0?e.agents.length:1;return`${H(e,"header",t)}${t("stream.codex.collab.agentCount",{count:i})}`}var V="\x01";function Z(e,t,i,a){let r=Object.fromEntries(Object.keys(a).map((o)=>[o,`${V}${o}${V}`]));return e(t,{...i,...r}).split(new RegExp(`${V}(\\w+)${V}`,"u")).map((o,d)=>n(ue,{children:d%2===1?a[o]:o},`${d}:${o}`))}function De({agent:e,showModel:t}){let{t:i,openSession:a}=L(),r=e.nickname??"",o=a===void 0?n("span",{className:"font-medium",children:r}):n("button",{type:"button",className:"codex-agent-link font-medium","aria-label":i("stream.codex.subagentOpen",{name:r}),onClick:()=>a(e.threadId,r),children:r});return p("span",{children:[o,e.role!==null&&` (${e.role})`,t&&ae(e.model,e.reasoningEffort,i)]})}function J({prompt:e}){return n("span",{className:"codex-collab-prompt",title:e,children:e})}function Oe(e,t){let i=e.prompt?.trim()?e.prompt:null,a=ie(e.status),r=e.tool==="spawnAgent"&&a==="completed"&&i!==null,o=(e.tool==="sendInput"||e.tool==="sendMessage"||e.tool==="followupTask")&&i!==null,d=Be(e),l=[];if(d.length===0)l.push({key:"generic",node:H(e,"row",t)});for(let c of d){let u=n(De,{agent:c,showModel:e.tool==="spawnAgent"});if(r)l.push({key:c.threadId,node:n("span",{className:"codex-collab-line",children:Z(t,"stream.codex.collab.createdWithInstructions",{},{agent:u,instructions:n(J,{prompt:i})})})});else if(o)l.push({key:c.threadId,node:n("span",{className:"codex-collab-line",children:Z(t,"stream.codex.collab.messagedWithPrompt",{action:a==="interrupted"?t("stream.codex.collab.interrupted"):t(`stream.codex.collab.messaged.${a}`)},{agent:u,prompt:n(J,{prompt:i})})})});else{let m=e.tool!=="closeAgent"&&e.tool!=="resumeAgent"&&c.state!==null&&c.state!==null?c.state.message?.trim()?t("stream.codex.collab.stateWithMessage",{state:t(`stream.codex.collab.state.${c.state.status}`),message:c.state.message}):t("stream.codex.collab.stateOnly",{state:t(`stream.codex.collab.state.${c.state.status}`)}):"";l.push({key:c.threadId,node:Z(t,"stream.codex.collab.agentRow",{action:H(e,"row",t),state:m},{agent:u})})}}if(!r&&!o&&i!==null)l.push({key:"input",node:Z(t,"stream.codex.collab.input",{},{prompt:n("span",{className:"codex-collab-input",children:i})})});return l}function oe({block:e}){let{t}=L(),[i,a]=E(`collab:${e.id}`,!1);if(e.tool==="wait")return null;let r=w(e.status),o=re(e,t);return p("div",{className:"codex-activity-item",children:[p("button",{type:"button",className:"codex-activity-header","data-codex-disclosure":"","aria-expanded":i,onClick:()=>a((d)=>!d),children:[p("span",{className:"codex-activity-label",children:[n(de,{className:"size-4 shrink-0","aria-hidden":"true"}),n("span",{className:"min-w-0 flex-1 truncate",children:r?n("span",{className:"codex-activity-running",children:o}):o})]}),n(_,{expanded:i})]}),n("div",{className:C("codex-activity-details-grid",i&&"codex-activity-details-grid-open"),children:n("div",{className:"min-h-0 overflow-hidden",children:n("div",{className:"codex-subagent-details",children:Oe(e,t).map((d)=>n("div",{className:"codex-collab-row",children:d.node},d.key))})})})]})}function se({block:e}){let{t,i18n:i}=L(),a=Boolean(e.isComplete),[r,o]=E(`thinking:${M(e)}:${a?"complete":"streaming"}`,!a),d=I(a),l=I(null);A(()=>{if(!a)o(!0);if(!d.current&&a)o(!1);d.current=a},[a,o]);let c=e.thinking.trim().length>0;A(()=>{if(a||!c)return;let m=l.current;if(m===null)throw Error("Thinking details are not mounted");let x=new ResizeObserver(()=>{m.scrollTop=m.scrollHeight}),h=null,y=()=>{let f=m.firstElementChild;if(f===h)return;if(h!==null)x.unobserve(h);if(h=f,h!==null)x.observe(h)},v=new MutationObserver(y);return v.observe(m,{childList:!0}),y(),()=>{v.disconnect(),x.disconnect()}},[c,a]);let u=a?e.durationMs!==void 0?t("stream.codex.thoughtFor",{duration:W(e.durationMs,i.language)}):t("stream.codex.thought"):t("message.thinking"),s=e.thinking.trimStart().replace(/^\*\*[^\n]*?\*\*\s*/,"");return p("div",{className:"codex-activity-item",children:[p("button",{type:"button",className:C("codex-activity-header",!c&&"codex-activity-header-static"),"data-codex-disclosure":"","aria-expanded":c?r:void 0,disabled:!c,onClick:()=>o((m)=>!m),children:[n("span",{className:"codex-activity-label",children:n("span",{className:"codex-reasoning-label min-w-0 flex-1 truncate",children:a?u:n("span",{className:"codex-activity-running",children:u})})}),c&&n(_,{expanded:r})]}),n("div",{className:C("codex-activity-details-grid",r&&"codex-activity-details-grid-open"),children:n("div",{className:"min-h-0 overflow-hidden",children:c&&n("div",{ref:l,className:"codex-reasoning-details",role:"region","aria-label":u,"aria-hidden":!r,tabIndex:0,inert:!r,children:n(X,{text:s,streaming:!a})})})})]})}function Ve(e){if(R(e))return"mcp";let t=O(e).category;return t==="think"||t==="switch_mode"?"other":t}function Ze(e,t,i,a){return a(`stream.codex.summary.${e}.${i?"leading":"following"}`,{count:t})}function je(e,t,i){let a=new Map;for(let o of e){let d=Ve(o);a.set(d,(a.get(d)??0)+1)}let r=Array.from(a,([o,d],l)=>Ze(o,d,l===0,t));if(i.startsWith("zh"))return r.join("");return new Intl.ListFormat(i,{style:"long",type:"conjunction"}).format(r)}function Ke({stateKey:e,durationMs:t,durationKind:i="work",active:a,startedAt:r,providerId:o,providerIcon:d,children:l}){let{t:c,i18n:u}=L(),[s,m]=E(`work:${e}`,a),x=P(`work:${e}`,s||a),h=I(a),y=I(null),[v,f]=D(0);A(()=>{if(a)m(!0);if(h.current&&!a)m(!1);h.current=a},[a,m]),A(()=>{if(!a||t!==void 0){y.current=null;return}y.current=r??Date.now();let N=()=>{let B=y.current;if(B===null)throw Error("Codex work section is ticking without a start time");f(Date.now()-B)};N();let F=window.setInterval(N,1000);return()=>window.clearInterval(F)},[a,r,t]);let S=t!==void 0?c(i==="total"?"stream.codex.totalDuration":"stream.codex.workedFor",{duration:W(t,u.language)}):a&&v>=1000?c("stream.codex.workedFor",{duration:W(v,u.language)}):c("stream.codex.worked");return p("section",{className:"codex-work-section",children:[p("button",{type:"button",className:"codex-work-trigger","data-codex-disclosure":"","aria-expanded":s,onClick:()=>m((N)=>!N),children:[o!==void 0&&n("span",{className:"codex-work-provider-icon","data-testid":"codex-work-provider-icon","data-provider-id":o,"aria-hidden":"true",children:d}),n("span",{children:S}),n(_,{expanded:s,className:"codex-work-chevron"})]}),n("div",{className:"codex-work-separator","aria-hidden":"true"}),n("div",{className:C("codex-work-grid",s&&"codex-work-grid-open"),children:n("div",{className:"min-h-0 overflow-hidden",children:n("div",{className:"codex-work-body",children:x&&l})})})]})}function We(e,t){if(e.type==="tool_use")return ve(e,t);if(e.type==="thinking")return t("message.thinking");if(e.type==="collab")return re(e,t);return t("stream.codex.subagentWorking",{name:e.name})}function Q(e){if(e.type==="thinking")return!e.isComplete;if(e.type==="tool_use"||e.type==="subagent"||e.type==="collab")return w(e.status);return!1}function He(e,t,i=1000){let[a,r]=D({text:e,live:t}),o=I(Date.now());return A(()=>{if(e===a.text&&t===a.live)return;let d=Date.now(),l=Math.max(0,o.current+i-d);if(l===0||t!==a.live){o.current=d,r({text:e,live:t});return}let c=window.setTimeout(()=>{o.current=Date.now(),r({text:e,live:t})},l);return()=>window.clearTimeout(c)},[a,t,i,e]),t===a.live?a.text:e}function Pe({blocks:e}){let{t,i18n:i}=L(),a=e.some(Q),r=e.map(M).join(":"),[o,d]=E(`group:${r}`,a),l=P(`group:${r}`,o||a),c=I(a);A(()=>{if(a)d(!0);if(c.current&&!a)d(!1);c.current=a},[a,d]);let u=e.findLast(Q)??e.at(-1);if(u===void 0)throw Error("CodexActivityGroup requires at least one activity block");let s=e.filter((x)=>x.type==="tool_use"),m=He(a?We(u,t):je(s,t,i.language),a);return p("div",{className:"codex-activity-group",children:[p("button",{type:"button",className:"codex-activity-group-trigger","aria-expanded":o,onClick:()=>d((x)=>!x),children:[p("span",{className:"codex-activity-label",children:[n(Y,{block:e[0]}),n("span",{className:"truncate",children:a?n("span",{className:"codex-activity-running",children:m}):m})]}),n(_,{expanded:o})]}),n("div",{className:C("codex-activity-group-grid",o&&"codex-activity-group-grid-open"),children:n("div",{className:"min-h-0 overflow-hidden",children:n("div",{className:"codex-activity-group-body",children:l&&e.map((x)=>n(te,{block:x},M(x)))})})})]})}function ke({blocks:e}){if(e.length===0)throw Error("CodexActivityGroup requires at least one activity block");if(e.length===1)return n(te,{block:e[0]});return n(Pe,{blocks:e})}export{ke as CodexActivityGroup,Ke as CodexWorkSection};
@@ -1,2 +1,2 @@
1
- import{jsx as n,jsxs as f}from"react/jsx-runtime";import{cn as B}from"cn";import{useActivityHost as C,ActivityMarkdown as k}from"../activity-host.js";import{groupBlocksForStyle as T}from"../lib/group-blocks.js";import{describeToolUse as j}from"../lib/stream-style.js";import{CodexActivityGroup as E,CodexWorkSection as S}from"./activity-group.js";import{CodexPlan as G}from"./plan.js";import{CodexEditedFilesCard as O}from"./edited-files-card.js";import{CopyAction as D}from"./user-message.js";var v=new WeakMap,H=1;function A(t){if(t.type==="tool_use"||t.type==="subagent"||t.type==="collab")return`${t.type}:${t.id}`;let i=v.get(t);if(i!==void 0)return`${t.type}:${i}`;let r=H++;return v.set(t,r),`${t.type}:${r}`}function K({block:t,streaming:i,actions:r}){if(t.isApiError)return n("div",{className:"codex-stream-error",children:t.text});return f("div",{className:"codex-assistant-message",children:[n(k,{text:t.text,streaming:i}),r]})}function P({block:t,streaming:i,actions:r,renderText:o}){switch(t.type){case"text":return o===void 0?n(K,{block:t,streaming:i,actions:r}):o({block:t,streaming:i,actions:r});case"thinking":return t.thinking.length>0?n(k,{text:t.thinking,streaming:!t.isComplete}):null;case"plan":return n(G,{entries:t.entries});case"image":return n("img",{src:`data:${t.source.media_type};base64,${t.source.data}`,className:"max-h-64 rounded",alt:""});case"tool_use":case"subagent":case"collab":return null}}var R=new Set;function Y({message:t,isMostRecentTurn:i,hiddenTools:r=R,time:o,beforeCopy:s,afterCopy:l,providerIcon:w,renderText:_,renderEditedFiles:m}){if(t.streaming===!0&&t.content.every((e)=>e.type==="text"?e.text.length===0:e.type==="thinking"?e.thinking.length===0:!1))return n(N,{});let g=t.content.filter((e)=>e.type==="text").map((e)=>e.text).join(`
2
- `),I=!t.streaming&&g.trim().length>0?n(W,{text:g,isMostRecentTurn:i,beforeCopy:s,afterCopy:l,time:o}):null,c=T(t.content,"compact"),u=c.reduce((e,a,d)=>a.kind==="codexActivityGroup"?d:e,-1),h=c.findIndex((e,a)=>a>u&&e.kind==="block"&&e.block.type==="text"),M=[...t.content].reverse().find((e)=>e.type==="text"),p=t.content.filter((e)=>e.type==="tool_use"&&j(e).category==="edit"),y=(e)=>{if(e.kind==="codexActivityGroup"){let a=e.blocks.filter((d)=>d.type!=="tool_use"||!r.has(d.name));return a.length===0?null:n(E,{blocks:a},`activity:${A(a[0])}`)}if(e.kind!=="block")throw Error(`Codex received an incompatible grouped entry: ${e.kind}`);return n(P,{block:e.block,streaming:Boolean(t.streaming),actions:e.block===M?I:void 0,renderText:_},A(e.block))},x=u===-1?0:h===-1?c.length:h;return n(F,{stateKey:t.id,active:Boolean(t.streaming),startedAt:t.startedAt,durationMs:t.durationMs,providerId:t.providerId,providerIcon:w,work:c.slice(0,x).map(y),answer:c.length>x?c.slice(x).map(y):null,footer:u!==-1&&p.length>0&&(m===void 0?n(O,{blocks:p}):m(p))})}function W({text:t,isMostRecentTurn:i=!1,beforeCopy:r,afterCopy:o,time:s}){let{t:l}=C();return f("div",{className:B("mt-1.5 flex h-5 w-fit -translate-x-1 items-center justify-start gap-0.5 [&_*]:transition-none",i?"opacity-100":"opacity-0 group-focus-within/am:opacity-100 group-hover/am:opacity-100"),children:[r,n(D,{text:t,label:l("actions.copy")}),o,s&&n("span",{className:"codex-user-time ms-1",title:s.full,children:s.short})]})}function N(){let{t}=C();return n("div",{className:"codex-pending-message py-2",role:"status",children:n("span",{className:"codex-activity-running",children:t("message.thinking")})})}function F({work:t,answer:i,footer:r,loading:o=!1,...s}){if(o)return n(N,{});return f("div",{className:"group/am codex-assistant-turn",children:[t.length>0&&n(S,{...s,children:t}),i!==null&&(t.length===0?i:n("div",{"data-local-conversation-final-assistant":!0,"data-testid":"codex-final-answer",className:"codex-final-answer",children:i})),r]})}export{Y as CodexAssistantMessage,F as CodexAssistantTurn,W as CodexMessageActions};
1
+ import{jsx as n,jsxs as f}from"react/jsx-runtime";import{cn as B}from"cn";import{ActivityMarkdown as C,useActivityHost as k}from"../activity-host.js";import{groupBlocksForStyle as T}from"../lib/group-blocks.js";import{describeToolUse as j}from"../lib/stream-style.js";import{CodexActivityGroup as E,CodexWorkSection as S}from"./activity-group.js";import{CodexEditedFilesCard as G}from"./edited-files-card.js";import{CodexPlan as O}from"./plan.js";import{CopyAction as D}from"./user-message.js";var v=new WeakMap,H=1;function A(t){if(t.type==="tool_use"||t.type==="subagent"||t.type==="collab")return`${t.type}:${t.id}`;let i=v.get(t);if(i!==void 0)return`${t.type}:${i}`;let r=H++;return v.set(t,r),`${t.type}:${r}`}function K({block:t,streaming:i,actions:r}){if(t.isApiError)return n("div",{className:"codex-stream-error",children:t.text});return f("div",{className:"codex-assistant-message",children:[n(C,{text:t.text,streaming:i}),r]})}function P({block:t,streaming:i,actions:r,renderText:o}){switch(t.type){case"text":return o===void 0?n(K,{block:t,streaming:i,actions:r}):o({block:t,streaming:i,actions:r});case"thinking":return t.thinking.length>0?n(C,{text:t.thinking,streaming:!t.isComplete}):null;case"plan":return n(O,{entries:t.entries});case"image":return n("img",{src:`data:${t.source.media_type};base64,${t.source.data}`,className:"max-h-64 rounded",alt:""});case"tool_use":case"subagent":case"collab":return null}}var R=new Set;function Y({message:t,isMostRecentTurn:i,hiddenTools:r=R,time:o,beforeCopy:s,afterCopy:l,providerIcon:w,renderText:_,renderEditedFiles:m}){if(t.streaming===!0&&t.content.every((e)=>e.type==="text"?e.text.length===0:e.type==="thinking"?e.thinking.length===0:!1))return n(N,{});let g=t.content.filter((e)=>e.type==="text").map((e)=>e.text).join(`
2
+ `),I=!t.streaming&&g.trim().length>0?n(W,{text:g,isMostRecentTurn:i,beforeCopy:s,afterCopy:l,time:o}):null,c=T(t.content,"compact"),u=c.reduce((e,a,d)=>a.kind==="codexActivityGroup"?d:e,-1),h=c.findIndex((e,a)=>a>u&&e.kind==="block"&&e.block.type==="text"),M=[...t.content].reverse().find((e)=>e.type==="text"),p=t.content.filter((e)=>e.type==="tool_use"&&j(e).category==="edit"),y=(e)=>{if(e.kind==="codexActivityGroup"){let a=e.blocks.filter((d)=>d.type!=="tool_use"||!r.has(d.name));return a.length===0?null:n(E,{blocks:a},`activity:${A(a[0])}`)}if(e.kind!=="block")throw Error(`Codex received an incompatible grouped entry: ${e.kind}`);return n(P,{block:e.block,streaming:Boolean(t.streaming),actions:e.block===M?I:void 0,renderText:_},A(e.block))},x=u===-1?0:h===-1?c.length:h;return n(F,{stateKey:t.id,active:Boolean(t.streaming),startedAt:t.startedAt,durationMs:t.durationMs,providerId:t.providerId,providerIcon:w,work:c.slice(0,x).map(y),answer:c.length>x?c.slice(x).map(y):null,footer:u!==-1&&p.length>0&&(m===void 0?n(G,{blocks:p}):m(p))})}function W({text:t,isMostRecentTurn:i=!1,beforeCopy:r,afterCopy:o,time:s}){let{t:l}=k();return f("div",{className:B("mt-1.5 flex h-5 w-fit -translate-x-1 items-center justify-start gap-0.5 [&_*]:transition-none",i?"opacity-100":"opacity-0 group-focus-within/am:opacity-100 group-hover/am:opacity-100"),children:[r,n(D,{text:t,label:l("actions.copy")}),o,s&&n("span",{className:"codex-user-time ms-1",title:s.full,children:s.short})]})}function N(){let{t}=k();return n("div",{className:"codex-pending-message py-2",role:"status",children:n("span",{className:"codex-activity-running",children:t("message.thinking")})})}function F({work:t,answer:i,footer:r,loading:o=!1,...s}){if(o)return n(N,{});return f("div",{className:"group/am codex-assistant-turn",children:[t.length>0&&n(S,{...s,children:t}),i!==null&&(t.length===0?i:n("div",{"data-local-conversation-final-assistant":!0,"data-testid":"codex-final-answer",className:"codex-final-answer",children:i})),r]})}export{Y as CodexAssistantMessage,F as CodexAssistantTurn,W as CodexMessageActions};
@@ -3,6 +3,7 @@ export interface MarkdownHost {
3
3
  theme: "dark" | "light";
4
4
  copyLabel: string;
5
5
  openLink: (url: string) => void;
6
+ preview?: boolean;
6
7
  }
7
8
  export declare function CodexMarkdownRenderer({ text, streaming, host }: {
8
9
  text: string;
@@ -1,6 +1,6 @@
1
- import{jsx as i,jsxs as h,Fragment as oe}from"react/jsx-runtime";import{decodeHTMLAttribute as M,decodeHTMLStrict as v}from"entities";import ae from"katex";import{CheckIcon as K,ChevronLeftIcon as ie,ChevronRightIcon as se,CopyIcon as ce,DownloadIcon as de,FileIcon as le,LinkIcon as ue,MailIcon as me,XIcon as he}from"lucide-react";import"katex/dist/katex.min.css";import{createElement as U,memo as H,startTransition as fe,useEffect as g,useLayoutEffect as X,useMemo as B,useRef as w,useState as p}from"react";import{createContext as pe,useContext as ge}from"react";import{createCodeHighlighter as we}from"../lib/code-highlighter.js";import{createMarkdownParser as ke}from"../lib/markdown-parser.js";import{isSafeMarkdownUrl as D}from"../lib/markdown-rules.js";var G=pe(null);function V(){let e=ge(G);if(e===null)throw Error("Markdown host is missing");return e}var xe=80,F=/\[([^\]\n]+)\]\(([^)\n]+)$/,be=/(^|\n)[^\S\n]*!\[[^\]\n]*(?:\](?:\([^\n]*)?)?\s*$/,Ce=/\uE200[^\uE201]*$/,Ne=4,Me=new Set("7zipx.accdb.asarpack.asciidoc.backup.backupdb.bundle.ccproj.cdrdao.code-workspace.config.debugin.deploy.design.docbook.dockerfile.dockerignore.editorconfig.eslintignore.gitattributes.gitignore.gitignore.gitkeep.gradle.graphqls.ignore.ipynb.keychain.keynote.licensee.lockfile.lockfile.markdown.markup.matlab.mkdocs.models.module.msstyle.notebook.npmignore.output.packageinfo.parquet.pickle.plistx.policy.postcssrc.prettierignore.projectfile.python.readme.review.robots.schema.search.series.settingsjson.shader.sqlite.sqlite3.storyboard.styles.system.target.terraform.update.vertex.webapp.webdoc.webpackrc.widget.workspace.xcodeproj.yarnlock".split("."));function E(e,n){let t=0;for(let r=n-1;r>=0&&e[r]==="\\";r-=1)t+=1;return t%2===1}function Z(e,n,t){if(t.length!==1)return!1;return e[n-1]===t||e[n+1]===t}function Ee(e,n){let t=0;for(let r=0;r<=e.length-n.length;){if(e.startsWith(n,r)&&!E(e,r)&&!Z(e,r,n)){t+=1,r+=n.length;continue}r+=1}return t}function Te(e,n){for(let t=e.length-n.length;t>=0;t-=1)if(e.startsWith(n,t)&&!E(e,t)&&!Z(e,t,n))return t;return-1}function $e(e,n){let t=0;for(let r=0;r<=e.length-n.length;){if(e.startsWith(n,r)&&!E(e,r)){t+=1,r+=n.length;continue}r+=1}return t}function ye(e){return $e(e,"```")%2===1}function J(e){let n=0;for(let t=0;t<e.length;){if(e.startsWith("```",t)){for(t+=3;t<e.length&&!e.startsWith("```",t);)t+=1;if(t<e.length)t+=3;continue}if(e[t]==="`"&&!E(e,t))n+=1;t+=1}return n%2===1}function Ie(e){return e.endsWith(`
1
+ import{jsx as a,jsxs as h,Fragment as U}from"react/jsx-runtime";import{decodeHTMLAttribute as M,decodeHTMLStrict as L}from"entities";import ae from"katex";import{CheckIcon as H,ChevronLeftIcon as ie,ChevronRightIcon as se,CopyIcon as ce,DownloadIcon as de,FileIcon as le,LinkIcon as ue,MailIcon as me,XIcon as he}from"lucide-react";import"katex/dist/katex.min.css";import{createContext as fe,createElement as B,memo as X,startTransition as pe,useContext as ge,useEffect as g,useLayoutEffect as D,useMemo as G,useRef as w,useState as p}from"react";import{createCodeHighlighter as we}from"../lib/code-highlighter.js";import{cachedMarkdown as ke,createMarkdownParser as xe}from"../lib/markdown-parser.js";import{isSafeMarkdownUrl as V}from"../lib/markdown-rules.js";var Z=fe(null);function v(){let e=ge(Z);if(e===null)throw Error("Markdown host is missing");return e}var be=80,j=/\[([^\]\n]+)\]\(([^)\n]+)$/,Ce=/(^|\n)[^\S\n]*!\[[^\]\n]*(?:\](?:\([^\n]*)?)?\s*$/,Ne=/\uE200[^\uE201]*$/,Me=4,ve=new Set("7zipx.accdb.asarpack.asciidoc.backup.backupdb.bundle.ccproj.cdrdao.code-workspace.config.debugin.deploy.design.docbook.dockerfile.dockerignore.editorconfig.eslintignore.gitattributes.gitignore.gitignore.gitkeep.gradle.graphqls.ignore.ipynb.keychain.keynote.licensee.lockfile.lockfile.markdown.markup.matlab.mkdocs.models.module.msstyle.notebook.npmignore.output.packageinfo.parquet.pickle.plistx.policy.postcssrc.prettierignore.projectfile.python.readme.review.robots.schema.search.series.settingsjson.shader.sqlite.sqlite3.storyboard.styles.system.target.terraform.update.vertex.webapp.webdoc.webpackrc.widget.workspace.xcodeproj.yarnlock".split("."));function E(e,n){let t=0;for(let r=n-1;r>=0&&e[r]==="\\";r-=1)t+=1;return t%2===1}function J(e,n,t){if(t.length!==1)return!1;return e[n-1]===t||e[n+1]===t}function Ee(e,n){let t=0;for(let r=0;r<=e.length-n.length;){if(e.startsWith(n,r)&&!E(e,r)&&!J(e,r,n)){t+=1,r+=n.length;continue}r+=1}return t}function Ie(e,n){for(let t=e.length-n.length;t>=0;t-=1)if(e.startsWith(n,t)&&!E(e,t)&&!J(e,t,n))return t;return-1}function Te(e,n){let t=0;for(let r=0;r<=e.length-n.length;){if(e.startsWith(n,r)&&!E(e,r)){t+=1,r+=n.length;continue}r+=1}return t}function $e(e){return Te(e,"```")%2===1}function Y(e){let n=0;for(let t=0;t<e.length;){if(e.startsWith("```",t)){for(t+=3;t<e.length&&!e.startsWith("```",t);)t+=1;if(t<e.length)t+=3;continue}if(e[t]==="`"&&!E(e,t))n+=1;t+=1}return n%2===1}function ye(e){return e.endsWith(`
2
2
  `)?`${e}\`\`\``:`${e}
3
- \`\`\``}function j(e,n){if(!e.includes(n)||Ee(e,n)%2===0)return e;let t=Te(e,n);if(t<0)return e;let r=e.slice(t+n.length);if(r.length===0||/^\s/.test(r)||r.includes(`
4
- `)||J(r))return e;return`${e}${n}`}function ve(e){return e.startsWith("/")&&!e.startsWith("//")||/^[A-Za-z]:[\\/]/.test(e)||/^\\\\[^\\]+\\[^\\]+/.test(e)||/^\/\/[^/]+\/[^/]+/.test(e)}function Y(e){let n=e.replace(/`/g,"").trim(),t=n.match(/^(.*?):(\d+)(?::(\d+))?(?:[-–](\d+)(?::(\d+))?)?$/);if(t!==null){let[,o,a,s,c,d]=t;if(o===void 0||a===void 0)throw Error("Codex file location is incomplete");return{path:o,line:Number.parseInt(a,10),column:s===void 0?void 0:Number.parseInt(s,10),endLine:c===void 0?void 0:Number.parseInt(c,10),endColumn:d===void 0?void 0:Number.parseInt(d,10)}}let r=n.match(/^(.*?)#L(\d+)(?:C(\d+))?(?:-L(\d+)(?:C(\d+))?)?$/);if(r!==null){let[,o,a,s,c,d]=r;if(o===void 0||a===void 0)throw Error("Codex hash file location is incomplete");return{path:o,line:Number.parseInt(a,10),column:s===void 0?void 0:Number.parseInt(s,10),endLine:c===void 0?void 0:Number.parseInt(c,10),endColumn:d===void 0?void 0:Number.parseInt(d,10)}}return{path:n}}function Le(e){let{path:n,line:t,column:r,endLine:o,endColumn:a}=Y(e);if(/^[a-z][a-z0-9+.-]*:\/\//i.test(n)||/^www\./i.test(n)||/^(mailto|tel):/i.test(n))return!1;if(t!==void 0||r!==void 0||o!==void 0||a!==void 0)return!0;if(!/(?:^|[\\/])[^\\/]+\.(?!\d+$)[^\\/.]+$/i.test(n))return!1;let s=/[\\/]/.test(n),c=n.split(/[\\/]/).at(-1);if(c===void 0)throw Error("Codex streaming link target has no file name");let d=c.split(".").at(-1);if(d===void 0||d.length===0)return!1;if(!s&&/[a-z]/.test(d)&&/[A-Z]/.test(d.slice(1)))return!1;if(!s){let u=d.toLowerCase();if(u.length>Ne&&!Me.has(u))return!1}return!0}function Se(e){let{path:n}=Y(e);if(ve(n))return!0;try{return new URL(n).protocol==="file:"}catch{return!1}}function _e(e){let n=e.match(F);if(n===null)return e;let t=n[2];if(t===void 0)throw Error("Codex streaming link target is missing");return Le(t)||Se(t)?e.replace(F,"$1"):`${e})`}function Ae(e){let n=e.replace(Ce,"");if(n.length===0||n.includes("`")&&J(n))return{isCodeFenceOpen:!1,markdown:n};if(n.includes("```")&&ye(n))return{isCodeFenceOpen:!0,markdown:Ie(n)};if(n.includes("!["))n=n.replace(be,(t,r)=>r);if(n.includes("]("))n=_e(n);return n=j(n,"**"),n=j(n,"*"),{isCodeFenceOpen:!1,markdown:n}}function Fe(e){return e?.type==="paragraph"&&"tokens"in e&&Array.isArray(e.tokens)}function O(e){return Fe(e)&&e.tokens.length===1&&e.tokens[0]?.type==="image"}function Q(e){for(let n=0;n<e.length;n+=1){let t=e[n];if(t===void 0)throw Error(`Codex Markdown token is missing at index ${n}`);if("tokens"in t&&Array.isArray(t.tokens))Q(t.tokens);if(!O(t))continue;let r=[...t.tokens],o=n+1,a=o;for(;;){while(e[o]?.type==="space")o+=1;let s=e[o];if(!O(s))break;r.push(...s.tokens),o+=1,a=o}if(a===n+1)continue;t.tokens=r,t.text=r.map((s)=>s.raw).join(`
5
- `),t.raw=e.slice(n,a).map((s)=>s.raw).join(""),e.splice(n+1,a-n-1)}}function R(e){return{type:"text",raw:e,text:e}}function je(e){return{type:"paragraph",raw:e.raw,text:e.text,tokens:e.tokens??[e]}}function I(e){for(let n of e){if(n.type==="list")for(let t of n.items){let r=t.tokens[0];if(r?.type==="heading"){let o=r.raw.trimEnd(),a=o.match(/^#{1,6}\s+/)?.[0];if(a!==void 0)t.tokens[0]={type:"paragraph",raw:r.raw,text:o,tokens:r.tokens===void 0?[R(o)]:[R(a),...r.tokens]}}if(t.loose)t.tokens=t.tokens.map((o)=>o.type==="text"?je(o):o);I(t.tokens)}if("tokens"in n&&Array.isArray(n.tokens))I(n.tokens)}}function Oe(e,n,t){e.preventDefault(),e.stopPropagation(),t.openLink(n)}function Re(e){try{let n=new URL(e);return n.protocol!=="http:"&&n.protocol!=="https:"?null:`${n.origin}/favicon.ico`}catch{return null}}function Pe(e){let n=Re(e);return n===null?[]:[n,`https://www.google.com/s2/favicons?domain=${new URL(e).origin}&sz=32`]}function qe({href:e}){let n=B(()=>Pe(e),[e]),[t,r]=p(),o=n.length===0&&!/^[a-z][a-z0-9+.-]*:/i.test(e),a=e.toLowerCase().startsWith("mailto:")?me:o?le:ue;return h("span",{className:"codex-markdown-favicon",children:[t===void 0?i("span",{className:"codex-markdown-favicon-fallback",children:i(a,{"aria-hidden":!0})}):null,n.map((s)=>i("img",{alt:"",className:t===s?"codex-markdown-favicon-image-loaded":void 0,decoding:"async",draggable:!1,referrerPolicy:"no-referrer",src:s,onLoad:()=>r((c)=>c!==void 0&&n.includes(c)?c:s)},s))]})}function We({children:e,href:n,title:t}){let r=V();return i("a",{className:"codex-markdown-link","data-inline-mention-interactive":"",href:n,title:t,onClick:(o)=>Oe(o,n,r),children:h("span",{className:"codex-markdown-link-mention","data-layout":"inline-flow","data-interactive":"","data-underline-on-hover":"",children:[i("span",{className:"codex-markdown-link-icon-container","data-markdown-copy":"exclude",children:i(qe,{href:n})}),i("span",{className:"codex-markdown-link-label",children:e})]})})}function ze({code:e,language:n}){let{theme:t,copyLabel:r}=V(),o=w(null),[a,s]=p(null),[c,d]=p(null),[u,k]=p(!1);if(g(()=>{let f=we(s,d);return o.current=f,()=>{f.dispose(),o.current=null}},[]),g(()=>{let f=o.current;if(f===null)throw Error("Code highlighter is not mounted");f.update(e,n)},[e,n]),c!==null)throw c;let b=a!==null&&a.code===e&&a.language===n?a.html:null,C=()=>{navigator.clipboard.writeText(e),k(!0),window.setTimeout(()=>k(!1),2000)};return h("div",{className:"codex-markdown-code-block","data-markdown-copy":"code-block","data-markdown-copy-text":e,"data-theme":t==="dark"?"dark":"light",children:[h("div",{className:"codex-markdown-code-header","data-markdown-copy":"exclude",children:[i("div",{className:"codex-markdown-code-title",children:n}),i("div",{className:"codex-markdown-code-actions",children:i("button",{type:"button",className:"codex-markdown-code-copy",title:r,onClick:C,children:u?i(K,{}):i(ce,{})})})]}),i("div",{className:"codex-markdown-code-container",dir:"ltr",children:i("code",{className:"codex-markdown-code-content hljs",...b===null?{children:e}:{dangerouslySetInnerHTML:{__html:b}}})})]})}function Ke({code:e,language:n}){let t=w(null),[r,o]=p(!1);if(g(()=>{if(r)return;let a=t.current;if(a===null)throw Error("Codex code block placeholder is not mounted");if(typeof IntersectionObserver>"u"){let c=window.setTimeout(()=>o(!0),0);return()=>window.clearTimeout(c)}let s=new IntersectionObserver((c)=>{if(!c.some((d)=>d.isIntersecting))return;o(!0),s.disconnect()},{rootMargin:"600px 0px"});return s.observe(a),()=>s.disconnect()},[r]),r)return i(ze,{code:e,language:n});return i("div",{ref:t,className:"codex-markdown-code-block",children:i("pre",{className:"codex-markdown-code-placeholder",children:i("code",{children:e})})})}function Ue(e){let n=Array.from(document.body.querySelectorAll('[data-markdown-image-preview-trigger="true"]')),t=n.map((o)=>{let a=o.querySelector("img");if(a===null)throw Error("Codex image preview trigger has no image");return{src:a.currentSrc||a.src,alt:a.alt}}),r=n.indexOf(e);if(r===-1)throw Error("Codex image preview trigger is outside the document");return{images:t,index:r}}function He({preview:e,setPreview:n}){let t=e.images[e.index];if(t===void 0)throw Error(`Codex image preview index is out of range: ${e.index}`);return h("div",{className:"codex-markdown-image-preview",children:[i("img",{src:t.src,alt:t.alt}),h("div",{className:"codex-markdown-image-preview-actions",children:[i("button",{type:"button","aria-label":"Previous image",disabled:e.index===0,onClick:()=>n({...e,index:e.index-1}),children:i(ie,{})}),i("a",{href:t.src,download:!0,"aria-label":"Download image",children:i(de,{})}),i("button",{type:"button","aria-label":"Next image",disabled:e.index===e.images.length-1,onClick:()=>n({...e,index:e.index+1}),children:i(se,{})}),i("button",{type:"button","aria-label":"Close image preview",onClick:()=>n(void 0),children:i(he,{})})]})]})}function Xe({src:e,alt:n,title:t,allowWide:r}){let o=w(null),[a,s]=p();g(()=>{let d=o.current;if(d===null)throw Error("Codex image preview dialog is not mounted");if(a===void 0){if(d.open)d.close();return}if(!d.open)d.showModal()},[a]);let c=n.length===0?"Open image preview":n;return h(oe,{children:[i("button",{type:"button",className:`codex-markdown-image-trigger${r?"codex-markdown-image-trigger-wide":""}`,"aria-label":c,"data-markdown-image-preview-trigger":"true",onClick:(d)=>s(Ue(d.currentTarget)),children:i("img",{className:`codex-markdown-image${r?"codex-markdown-image-wide":""}`,src:e,alt:n,title:t,loading:"lazy"})}),i("dialog",{ref:o,className:"codex-markdown-image-dialog","aria-label":c,onClose:()=>s(void 0),children:a===void 0?null:i(He,{preview:a,setPreview:s})})]})}function Be({value:e,display:n}){let t=w(null);return X(()=>{if(t.current===null)throw Error("Codex math root is not mounted");ae.render(e,t.current,{displayMode:n,throwOnError:!1})},[n,e]),i("span",{ref:t,className:n?"codex-markdown-math-block":"codex-markdown-inline-math"})}var De=150,N=null;function P(e,n){let t=N;if(t===null)return e;let r=t.cursor,o=r+e.length;t.cursor=o;let a=[],s=r;for(let c of t.runs){if(c.end<=r)continue;if(c.start>=o)break;let d=Math.max(r,c.start),u=Math.min(o,c.end);if(s<d)a.push(e.slice(s-r,d-r));a.push(i("span",{className:"codex-markdown-fade",children:e.slice(d-r,u-r)},`${n}:${t.generation}:${c.start}`)),s=u}if(s<o)a.push(e.slice(s-r));return a}function ee(e){let n=5381;for(let t=0;t<e.length;t+=1)n=(n*33+e.charCodeAt(t))%4294967296;return n.toString(36)}function q(e){let n=e.trim();if(n.length===0)return"";let t=n.split(`
6
- `,1)[0];if(t===void 0)throw Error("Codex Markdown token has no first line");let r=t.match(/\S+/)?.[0];return(r===void 0?t:r).slice(0,xe)}function Ge(e){switch(e.type){case"code":return e.raw.trimStart().match(/^(```|~~~)/)?.[1]??"";case"link":return e.href;case"image":{let n=e;return`${n.href}:${q(n.text)}`}case"html":case"space":case"br":case"hr":case"def":return e.raw;case"math":return q(e.text);default:return""}}function ne(e){return`${e.type==="math"?`math-${e.display?"block":"inline"}`:e.type}-${ee(Ge(e))}`}function m(e,n){let t=new Map;return e.map((r)=>{let o=ne(r),a=t.get(o)??0;return t.set(o,a+1),te(r,`${n}-${o}-${a}`)})}function Ve(e,n){let t=e.task?e.tokens.filter((r)=>r.type!=="checkbox"):e.tokens;return h("li",{className:`codex-markdown-list-item${e.task?"codex-markdown-task-list-item":""}`,children:[e.task?h("div",{className:"codex-markdown-task-checkbox",children:[i("input",{type:"checkbox",className:"codex-markdown-checkbox",checked:e.checked,"data-state":e.checked?"checked":"unchecked",readOnly:!0,disabled:!0}),e.checked?i(K,{}):null]}):null,m(t,n)]},n)}function Ze(e,n){let r=`codex-markdown-list ${e.items.some((a)=>a.task)?"codex-markdown-task-list":e.ordered?"codex-markdown-ordered-list":"codex-markdown-unordered-list"}`,o=m(e.items,n);return e.ordered?i("ol",{className:r,start:e.start===""?void 0:e.start,children:o},n):i("ul",{className:r,children:o},n)}function W(e,n,t){let r=t?"th":"td",o=/^\d+$/.test(e.text);return U(r,{key:n,className:`${t?"codex-markdown-table-header":"codex-markdown-table-cell"}${o?" codex-markdown-numeric-table-cell":""}`,align:e.align??void 0},...m(e.tokens,n))}function Je(e,n){let t=new Map;return i("div",{className:"codex-markdown-table-container","data-markdown-table":!0,tabIndex:-1,children:i("div",{className:"codex-markdown-table-scroller",children:i("div",{className:"codex-markdown-table-wrapper",children:h("table",{className:"codex-markdown-table",children:[i("thead",{children:i("tr",{className:"codex-markdown-table-row",children:e.header.map((r,o)=>W(r,`${n}-header-${o}`,!0))})}),i("tbody",{className:"codex-markdown-table-body",children:e.rows.map((r)=>{let o=ee(r.map((c)=>c.text).join("\x00")),a=t.get(o)??0;t.set(o,a+1);let s=`${n}-row-${o}-${a}`;return i("tr",{className:"codex-markdown-table-row",children:r.map((c,d)=>W(c,`${s}-cell-${d}`,!1))},s)})})]})})})},n)}function z(e,n,t){let r=M(e.href);if(!D(r))return null;return i(Xe,{src:r,alt:v(e.text),title:e.title==null?void 0:M(e.title),allowWide:t},n)}function te(e,n){switch(e.type){case"space":case"def":case"internalMessage":return null;case"hr":return i("hr",{className:"codex-markdown-horizontal-rule"},n);case"heading":{let t=e,o={1:"h1",2:"h2",3:"h3",4:"h4",5:"h5",6:"h6"}[t.depth];if(o===void 0)throw Error(`Unsupported Codex Markdown heading depth: ${t.depth}`);return U(o,{key:n,className:`codex-markdown-heading codex-markdown-heading-${t.depth}`},...m(t.tokens,n))}case"paragraph":{let t=e,r=t.tokens.filter((s)=>s.type!=="space"&&s.type!=="br"),o=r.length>0&&r.every((s)=>s.type==="image"),a=o&&r.length>1;return i("p",{className:`codex-markdown-paragraph${o?"codex-markdown-media-paragraph codex-markdown-media-wide-block":""}${a?"codex-markdown-media-grid-paragraph":""}`,"data-markdown-image-grid":a?"true":void 0,"data-wide-markdown-block":o?"true":void 0,"data-wide-markdown-block-kind":o?"image":void 0,children:o?r.map((s,c)=>z(s,`${n}-image-${c}`,!0)):m(t.tokens,n)},n)}case"text":{let t=e;return t.tokens===void 0?P(v(t.text),n):m(t.tokens,n)}case"escape":return P(e.text,n);case"strong":return i("strong",{className:"codex-markdown-strong",children:m(e.tokens,n)},n);case"em":return i("em",{children:m(e.tokens,n)},n);case"del":return i("del",{children:m(e.tokens,n)},n);case"codespan":return i("span",{className:"codex-markdown-inline-code",dir:"ltr","data-markdown-copy":"inline-code",children:e.text},n);case"br":return i("br",{},n);case"link":{let t=e,r=m(t.tokens,n),o=M(t.href);return D(o)?i(We,{href:o,title:t.title==null?void 0:M(t.title),children:r},n):i("span",{children:r},n)}case"image":return z(e,n,!1);case"code":{let t=e;return i(Ke,{code:t.text,language:t.lang},n)}case"blockquote":return i("blockquote",{className:"codex-markdown-blockquote",children:m(e.tokens,n)},n);case"list":return Ze(e,n);case"list_item":return Ve(e,n);case"table":return Je(e,n);case"html":{let t=e;return/^<br\s*\/?>$/i.test(t.raw.trim())?i("br",{},n):t.raw}case"math":{let t=e;return i(Be,{value:t.text,display:t.display},n)}default:throw Error(`Unsupported Codex Markdown token: ${JSON.stringify(e)}`)}}function x(e){switch(e.type){case"text":{let n=e;return n.tokens===void 0?v(n.text):n.tokens.map(x).join("")}case"escape":return e.text;case"paragraph":case"heading":case"strong":case"em":case"del":case"link":case"blockquote":case"list_item":return e.tokens.map(x).join("");case"list":return e.items.map(x).join("");case"table":{let n=e;return[n.header,...n.rows].map((t)=>t.map((r)=>r.tokens.map(x).join("")).join("")).join("")}default:return""}}function Ye({token:e,tokenKey:n,offset:t,runs:r,generation:o}){let a=N;try{return N={cursor:t,runs:r,generation:o},te(e,n)}finally{N=a}}var Qe=H(function({result:n}){let{text:t,isStreaming:r}=n,o=B(()=>{let l=n.tokens;if(n.source.includes("!["))Q(l);I(l);let L=new Map,S=0;return l.map((T)=>{let y=ne(T),_=L.get(y)??0;L.set(y,_+1);let A=x(T),re={token:T,tokenKey:`root-${y}-${_}`,offset:S,visibleText:A};return S+=A.length,re})},[n]),a=o.map((l)=>l.visibleText).join(""),s=w({text:"",visibleText:"",runs:[],generation:0}),c=s.current,d=t.startsWith(c.text)||a.startsWith(c.visibleText),u=d?c.visibleText.length:0,k=performance.now(),b=r&&d?c.runs.filter((l)=>k-l.firstSeenAtMs<De):[],C=c.generation+(d?0:1),f={text:t,visibleText:a,runs:b.filter((l)=>l.start<a.length).map((l)=>({...l,end:Math.min(l.end,a.length)})),generation:C};if(r&&a.length>u)f.runs.push({start:u,end:a.length,firstSeenAtMs:k});return X(()=>{s.current=f}),i("div",{dir:"auto",className:"codex-markdown-content codex-markdown-root","data-streaming":r?"true":void 0,children:o.map((l)=>i(Ye,{token:l.token,tokenKey:l.tokenKey,offset:l.offset,runs:f.runs,generation:C},l.tokenKey))})}),en=H(function({text:n,isStreaming:t}){let r=w(null),[o,a]=p(null),[s,c]=p(null);if(g(()=>{let d=ke((u)=>{fe(()=>a(u))},c);return r.current=d,()=>{d.dispose(),r.current=null}},[]),g(()=>{let d=r.current;if(d===null)throw Error("Markdown parser is not mounted");let u=t?Ae(n).markdown:n;d.update({source:u,text:n,isStreaming:t})},[t,n]),s!==null)throw s;return o===null?i("div",{"data-markdown-pending":!0}):i(Qe,{result:o})});function mn({text:e,streaming:n,host:t}){let r=n===!0,[o,a]=p(e);return g(()=>{if(o===e)return;if(!r){a(e);return}let s=requestAnimationFrame(()=>a(e));return()=>cancelAnimationFrame(s)},[o,r,e]),i(G.Provider,{value:t,children:i(en,{text:r?o:e,isStreaming:r})})}export{mn as CodexMarkdownRenderer};
3
+ \`\`\``}function O(e,n){if(!e.includes(n)||Ee(e,n)%2===0)return e;let t=Ie(e,n);if(t<0)return e;let r=e.slice(t+n.length);if(r.length===0||/^\s/.test(r)||r.includes(`
4
+ `)||Y(r))return e;return`${e}${n}`}function Le(e){return e.startsWith("/")&&!e.startsWith("//")||/^[A-Za-z]:[\\/]/.test(e)||/^\\\\[^\\]+\\[^\\]+/.test(e)||/^\/\/[^/]+\/[^/]+/.test(e)}function Q(e){let n=e.replace(/`/g,"").trim(),t=n.match(/^(.*?):(\d+)(?::(\d+))?(?:[-–](\d+)(?::(\d+))?)?$/);if(t!==null){let[,o,i,s,c,d]=t;if(o===void 0||i===void 0)throw Error("Codex file location is incomplete");return{path:o,line:Number.parseInt(i,10),column:s===void 0?void 0:Number.parseInt(s,10),endLine:c===void 0?void 0:Number.parseInt(c,10),endColumn:d===void 0?void 0:Number.parseInt(d,10)}}let r=n.match(/^(.*?)#L(\d+)(?:C(\d+))?(?:-L(\d+)(?:C(\d+))?)?$/);if(r!==null){let[,o,i,s,c,d]=r;if(o===void 0||i===void 0)throw Error("Codex hash file location is incomplete");return{path:o,line:Number.parseInt(i,10),column:s===void 0?void 0:Number.parseInt(s,10),endLine:c===void 0?void 0:Number.parseInt(c,10),endColumn:d===void 0?void 0:Number.parseInt(d,10)}}return{path:n}}function _e(e){let{path:n,line:t,column:r,endLine:o,endColumn:i}=Q(e);if(/^[a-z][a-z0-9+.-]*:\/\//i.test(n)||/^www\./i.test(n)||/^(mailto|tel):/i.test(n))return!1;if(t!==void 0||r!==void 0||o!==void 0||i!==void 0)return!0;if(!/(?:^|[\\/])[^\\/]+\.(?!\d+$)[^\\/.]+$/i.test(n))return!1;let s=/[\\/]/.test(n),c=n.split(/[\\/]/).at(-1);if(c===void 0)throw Error("Codex streaming link target has no file name");let d=c.split(".").at(-1);if(d===void 0||d.length===0)return!1;if(!s&&/[a-z]/.test(d)&&/[A-Z]/.test(d.slice(1)))return!1;if(!s){let u=d.toLowerCase();if(u.length>Me&&!ve.has(u))return!1}return!0}function Se(e){let{path:n}=Q(e);if(Le(n))return!0;try{return new URL(n).protocol==="file:"}catch{return!1}}function Ae(e){let n=e.match(j);if(n===null)return e;let t=n[2];if(t===void 0)throw Error("Codex streaming link target is missing");return _e(t)||Se(t)?e.replace(j,"$1"):`${e})`}function Fe(e){let n=e.replace(Ne,"");if(n.length===0||n.includes("`")&&Y(n))return{isCodeFenceOpen:!1,markdown:n};if(n.includes("```")&&$e(n))return{isCodeFenceOpen:!0,markdown:ye(n)};if(n.includes("!["))n=n.replace(Ce,(t,r)=>r);if(n.includes("]("))n=Ae(n);return n=O(n,"**"),n=O(n,"*"),{isCodeFenceOpen:!1,markdown:n}}function je(e){return e?.type==="paragraph"&&"tokens"in e&&Array.isArray(e.tokens)}function R(e){return je(e)&&e.tokens.length===1&&e.tokens[0]?.type==="image"}function ee(e){for(let n=0;n<e.length;n+=1){let t=e[n];if(t===void 0)throw Error(`Codex Markdown token is missing at index ${n}`);if("tokens"in t&&Array.isArray(t.tokens))ee(t.tokens);if(!R(t))continue;let r=[...t.tokens],o=n+1,i=o;for(;;){while(e[o]?.type==="space")o+=1;let s=e[o];if(!R(s))break;r.push(...s.tokens),o+=1,i=o}if(i===n+1)continue;t.tokens=r,t.text=r.map((s)=>s.raw).join(`
5
+ `),t.raw=e.slice(n,i).map((s)=>s.raw).join(""),e.splice(n+1,i-n-1)}}function P(e){return{type:"text",raw:e,text:e}}function Oe(e){return{type:"paragraph",raw:e.raw,text:e.text,tokens:e.tokens??[e]}}function y(e){for(let n of e){if(n.type==="list")for(let t of n.items){let r=t.tokens[0];if(r?.type==="heading"){let o=r.raw.trimEnd(),i=o.match(/^#{1,6}\s+/)?.[0];if(i!==void 0)t.tokens[0]={type:"paragraph",raw:r.raw,text:o,tokens:r.tokens===void 0?[P(o)]:[P(i),...r.tokens]}}if(t.loose)t.tokens=t.tokens.map((o)=>o.type==="text"?Oe(o):o);y(t.tokens)}if("tokens"in n&&Array.isArray(n.tokens))y(n.tokens)}}function Re(e,n,t){e.preventDefault(),e.stopPropagation(),t.openLink(n)}function Pe(e){try{let n=new URL(e);return n.protocol!=="http:"&&n.protocol!=="https:"?null:`${n.origin}/favicon.ico`}catch{return null}}function qe(e){let n=Pe(e);return n===null?[]:[n,`https://www.google.com/s2/favicons?domain=${new URL(e).origin}&sz=32`]}function We({href:e}){let n=G(()=>qe(e),[e]),[t,r]=p(),o=n.length===0&&!/^[a-z][a-z0-9+.-]*:/i.test(e),i=e.toLowerCase().startsWith("mailto:")?me:o?le:ue;return h("span",{className:"codex-markdown-favicon",children:[t===void 0?a("span",{className:"codex-markdown-favicon-fallback",children:a(i,{"aria-hidden":!0})}):null,n.map((s)=>a("img",{alt:"",className:t===s?"codex-markdown-favicon-image-loaded":void 0,decoding:"async",draggable:!1,referrerPolicy:"no-referrer",src:s,onLoad:()=>r((c)=>c!==void 0&&n.includes(c)?c:s)},s))]})}function ze({children:e,href:n,title:t}){let r=v();if(r.preview)return a("span",{children:e});return a("a",{className:"codex-markdown-link","data-inline-mention-interactive":"",href:n,title:t,onClick:(o)=>Re(o,n,r),children:h("span",{className:"codex-markdown-link-mention","data-layout":"inline-flow","data-interactive":"","data-underline-on-hover":"",children:[a("span",{className:"codex-markdown-link-icon-container","data-markdown-copy":"exclude",children:a(We,{href:n})}),a("span",{className:"codex-markdown-link-label",children:e})]})})}function Ke({code:e,language:n}){let{theme:t,copyLabel:r}=v(),o=w(null),[i,s]=p(null),[c,d]=p(null),[u,k]=p(!1);if(g(()=>{let f=we(s,d);return o.current=f,()=>{f.dispose(),o.current=null}},[]),g(()=>{let f=o.current;if(f===null)throw Error("Code highlighter is not mounted");f.update(e,n)},[e,n]),c!==null)throw c;let b=i!==null&&i.code===e&&i.language===n?i.html:null,C=()=>{navigator.clipboard.writeText(e),k(!0),window.setTimeout(()=>k(!1),2000)};return h("div",{className:"codex-markdown-code-block","data-markdown-copy":"code-block","data-markdown-copy-text":e,"data-theme":t==="dark"?"dark":"light",children:[h("div",{className:"codex-markdown-code-header","data-markdown-copy":"exclude",children:[a("div",{className:"codex-markdown-code-title",children:n}),a("div",{className:"codex-markdown-code-actions",children:a("button",{type:"button",className:"codex-markdown-code-copy",title:r,onClick:C,children:u?a(H,{}):a(ce,{})})})]}),a("div",{className:"codex-markdown-code-container",dir:"ltr",children:a("code",{className:"codex-markdown-code-content hljs",...b===null?{children:e}:{dangerouslySetInnerHTML:{__html:b}}})})]})}function Ue({code:e,language:n}){return v().preview?a("span",{children:e}):a(He,{code:e,language:n})}function He({code:e,language:n}){let t=w(null),[r,o]=p(!1);if(g(()=>{if(r)return;let i=t.current;if(i===null)throw Error("Codex code block placeholder is not mounted");if(typeof IntersectionObserver>"u"){let c=window.setTimeout(()=>o(!0),0);return()=>window.clearTimeout(c)}let s=new IntersectionObserver((c)=>{if(!c.some((d)=>d.isIntersecting))return;o(!0),s.disconnect()},{rootMargin:"600px 0px"});return s.observe(i),()=>s.disconnect()},[r]),r)return a(Ke,{code:e,language:n});return a("div",{ref:t,className:"codex-markdown-code-block",children:a("pre",{className:"codex-markdown-code-placeholder",children:a("code",{children:e})})})}function Be(e){let n=Array.from(document.body.querySelectorAll('[data-markdown-image-preview-trigger="true"]')),t=n.map((o)=>{let i=o.querySelector("img");if(i===null)throw Error("Codex image preview trigger has no image");return{src:i.currentSrc||i.src,alt:i.alt}}),r=n.indexOf(e);if(r===-1)throw Error("Codex image preview trigger is outside the document");return{images:t,index:r}}function Xe({preview:e,setPreview:n}){let t=e.images[e.index];if(t===void 0)throw Error(`Codex image preview index is out of range: ${e.index}`);return h("div",{className:"codex-markdown-image-preview",children:[a("img",{src:t.src,alt:t.alt}),h("div",{className:"codex-markdown-image-preview-actions",children:[a("button",{type:"button","aria-label":"Previous image",disabled:e.index===0,onClick:()=>n({...e,index:e.index-1}),children:a(ie,{})}),a("a",{href:t.src,download:!0,"aria-label":"Download image",children:a(de,{})}),a("button",{type:"button","aria-label":"Next image",disabled:e.index===e.images.length-1,onClick:()=>n({...e,index:e.index+1}),children:a(se,{})}),a("button",{type:"button","aria-label":"Close image preview",onClick:()=>n(void 0),children:a(he,{})})]})]})}function De(e){return v().preview?a(U,{children:e.alt}):a(Ge,{...e})}function Ge({src:e,alt:n,title:t,allowWide:r}){let o=w(null),[i,s]=p();g(()=>{let d=o.current;if(d===null)throw Error("Codex image preview dialog is not mounted");if(i===void 0){if(d.open)d.close();return}if(!d.open)d.showModal()},[i]);let c=n.length===0?"Open image preview":n;return h(U,{children:[a("button",{type:"button",className:`codex-markdown-image-trigger${r?"codex-markdown-image-trigger-wide":""}`,"aria-label":c,"data-markdown-image-preview-trigger":"true",onClick:(d)=>s(Be(d.currentTarget)),children:a("img",{className:`codex-markdown-image${r?"codex-markdown-image-wide":""}`,src:e,alt:n,title:t,loading:"lazy"})}),a("dialog",{ref:o,className:"codex-markdown-image-dialog","aria-label":c,onClose:()=>s(void 0),children:i===void 0?null:a(Xe,{preview:i,setPreview:s})})]})}function Ve({value:e,display:n}){let t=w(null);return D(()=>{if(t.current===null)throw Error("Codex math root is not mounted");ae.render(e,t.current,{displayMode:n,throwOnError:!1})},[n,e]),a("span",{ref:t,className:n?"codex-markdown-math-block":"codex-markdown-inline-math"})}var Ze=150,N=null;function q(e,n){let t=N;if(t===null)return e;let r=t.cursor,o=r+e.length;t.cursor=o;let i=[],s=r;for(let c of t.runs){if(c.end<=r)continue;if(c.start>=o)break;let d=Math.max(r,c.start),u=Math.min(o,c.end);if(s<d)i.push(e.slice(s-r,d-r));i.push(a("span",{className:"codex-markdown-fade",children:e.slice(d-r,u-r)},`${n}:${t.generation}:${c.start}`)),s=u}if(s<o)i.push(e.slice(s-r));return i}function ne(e){let n=5381;for(let t=0;t<e.length;t+=1)n=(n*33+e.charCodeAt(t))%4294967296;return n.toString(36)}function W(e){let n=e.trim();if(n.length===0)return"";let t=n.split(`
6
+ `,1)[0];if(t===void 0)throw Error("Codex Markdown token has no first line");let r=t.match(/\S+/)?.[0];return(r===void 0?t:r).slice(0,be)}function Je(e){switch(e.type){case"code":return e.raw.trimStart().match(/^(```|~~~)/)?.[1]??"";case"link":return e.href;case"image":{let n=e;return`${n.href}:${W(n.text)}`}case"html":case"space":case"br":case"hr":case"def":return e.raw;case"math":return W(e.text);default:return""}}function te(e){return`${e.type==="math"?`math-${e.display?"block":"inline"}`:e.type}-${ne(Je(e))}`}function m(e,n){let t=new Map;return e.map((r)=>{let o=te(r),i=t.get(o)??0;return t.set(o,i+1),re(r,`${n}-${o}-${i}`)})}function Ye(e,n){let t=e.task?e.tokens.filter((r)=>r.type!=="checkbox"):e.tokens;return h("li",{className:`codex-markdown-list-item${e.task?"codex-markdown-task-list-item":""}`,children:[e.task?h("div",{className:"codex-markdown-task-checkbox",children:[a("input",{type:"checkbox",className:"codex-markdown-checkbox",checked:e.checked,"data-state":e.checked?"checked":"unchecked",readOnly:!0,disabled:!0}),e.checked?a(H,{}):null]}):null,m(t,n)]},n)}function Qe(e,n){let r=`codex-markdown-list ${e.items.some((i)=>i.task)?"codex-markdown-task-list":e.ordered?"codex-markdown-ordered-list":"codex-markdown-unordered-list"}`,o=m(e.items,n);return e.ordered?a("ol",{className:r,start:e.start===""?void 0:e.start,children:o},n):a("ul",{className:r,children:o},n)}function z(e,n,t){let r=t?"th":"td",o=/^\d+$/.test(e.text);return B(r,{key:n,className:`${t?"codex-markdown-table-header":"codex-markdown-table-cell"}${o?" codex-markdown-numeric-table-cell":""}`,align:e.align??void 0},...m(e.tokens,n))}function en(e,n){let t=new Map;return a("div",{className:"codex-markdown-table-container","data-markdown-table":!0,tabIndex:-1,children:a("div",{className:"codex-markdown-table-scroller",children:a("div",{className:"codex-markdown-table-wrapper",children:h("table",{className:"codex-markdown-table",children:[a("thead",{children:a("tr",{className:"codex-markdown-table-row",children:e.header.map((r,o)=>z(r,`${n}-header-${o}`,!0))})}),a("tbody",{className:"codex-markdown-table-body",children:e.rows.map((r)=>{let o=ne(r.map((c)=>c.text).join("\x00")),i=t.get(o)??0;t.set(o,i+1);let s=`${n}-row-${o}-${i}`;return a("tr",{className:"codex-markdown-table-row",children:r.map((c,d)=>z(c,`${s}-cell-${d}`,!1))},s)})})]})})})},n)}function K(e,n,t){let r=M(e.href);if(!V(r))return null;return a(De,{src:r,alt:L(e.text),title:e.title==null?void 0:M(e.title),allowWide:t},n)}function re(e,n){switch(e.type){case"space":case"def":case"internalMessage":return null;case"hr":return a("hr",{className:"codex-markdown-horizontal-rule"},n);case"heading":{let t=e,o={1:"h1",2:"h2",3:"h3",4:"h4",5:"h5",6:"h6"}[t.depth];if(o===void 0)throw Error(`Unsupported Codex Markdown heading depth: ${t.depth}`);return B(o,{key:n,className:`codex-markdown-heading codex-markdown-heading-${t.depth}`},...m(t.tokens,n))}case"paragraph":{let t=e,r=t.tokens.filter((s)=>s.type!=="space"&&s.type!=="br"),o=r.length>0&&r.every((s)=>s.type==="image"),i=o&&r.length>1;return a("p",{className:`codex-markdown-paragraph${o?"codex-markdown-media-paragraph codex-markdown-media-wide-block":""}${i?"codex-markdown-media-grid-paragraph":""}`,"data-markdown-image-grid":i?"true":void 0,"data-wide-markdown-block":o?"true":void 0,"data-wide-markdown-block-kind":o?"image":void 0,children:o?r.map((s,c)=>K(s,`${n}-image-${c}`,!0)):m(t.tokens,n)},n)}case"text":{let t=e;return t.tokens===void 0?q(L(t.text),n):m(t.tokens,n)}case"escape":return q(e.text,n);case"strong":return a("strong",{className:"codex-markdown-strong",children:m(e.tokens,n)},n);case"em":return a("em",{children:m(e.tokens,n)},n);case"del":return a("del",{children:m(e.tokens,n)},n);case"codespan":return a("span",{className:"codex-markdown-inline-code",dir:"ltr","data-markdown-copy":"inline-code",children:e.text},n);case"br":return a("br",{},n);case"link":{let t=e,r=m(t.tokens,n),o=M(t.href);return V(o)?a(ze,{href:o,title:t.title==null?void 0:M(t.title),children:r},n):a("span",{children:r},n)}case"image":return K(e,n,!1);case"code":{let t=e;return a(Ue,{code:t.text,language:t.lang},n)}case"blockquote":return a("blockquote",{className:"codex-markdown-blockquote",children:m(e.tokens,n)},n);case"list":return Qe(e,n);case"list_item":return Ye(e,n);case"table":return en(e,n);case"html":{let t=e;return/^<br\s*\/?>$/i.test(t.raw.trim())?a("br",{},n):t.raw}case"math":{let t=e;return a(Ve,{value:t.text,display:t.display},n)}default:throw Error(`Unsupported Codex Markdown token: ${JSON.stringify(e)}`)}}function x(e){switch(e.type){case"text":{let n=e;return n.tokens===void 0?L(n.text):n.tokens.map(x).join("")}case"escape":return e.text;case"paragraph":case"heading":case"strong":case"em":case"del":case"link":case"blockquote":case"list_item":return e.tokens.map(x).join("");case"list":return e.items.map(x).join("");case"table":{let n=e;return[n.header,...n.rows].map((t)=>t.map((r)=>r.tokens.map(x).join("")).join("")).join("")}default:return""}}function nn({token:e,tokenKey:n,offset:t,runs:r,generation:o}){let i=N;try{return N={cursor:t,runs:r,generation:o},re(e,n)}finally{N=i}}var tn=X(function({result:n}){let{text:t,isStreaming:r}=n,o=G(()=>{let l=n.tokens;if(n.source.includes("!["))ee(l);y(l);let _=new Map,S=0;return l.map((I)=>{let T=te(I),A=_.get(T)??0;_.set(T,A+1);let F=x(I),oe={token:I,tokenKey:`root-${T}-${A}`,offset:S,visibleText:F};return S+=F.length,oe})},[n]),i=o.map((l)=>l.visibleText).join(""),s=w({text:"",visibleText:"",runs:[],generation:0}),c=s.current,d=t.startsWith(c.text)||i.startsWith(c.visibleText),u=d?c.visibleText.length:0,k=performance.now(),b=r&&d?c.runs.filter((l)=>k-l.firstSeenAtMs<Ze):[],C=c.generation+(d?0:1),f={text:t,visibleText:i,runs:b.filter((l)=>l.start<i.length).map((l)=>({...l,end:Math.min(l.end,i.length)})),generation:C};if(r&&i.length>u)f.runs.push({start:u,end:i.length,firstSeenAtMs:k});return D(()=>{s.current=f}),a("div",{dir:"auto",className:"codex-markdown-content codex-markdown-root","data-streaming":r?"true":void 0,children:o.map((l)=>a(nn,{token:l.token,tokenKey:l.tokenKey,offset:l.offset,runs:f.runs,generation:C},l.tokenKey))})}),rn=X(function({text:n,isStreaming:t}){let r=w(null),[o,i]=p(()=>ke(n,t)),[s,c]=p(null);if(g(()=>{let d=xe((u)=>{pe(()=>i(u))},c);return r.current=d,()=>{d.dispose(),r.current=null}},[]),g(()=>{let d=r.current;if(d===null)throw Error("Markdown parser is not mounted");let u=t?Fe(n).markdown:n;d.update({source:u,text:n,isStreaming:t})},[t,n]),s!==null)throw s;return o===null?a("div",{"data-markdown-pending":!0}):a(tn,{result:o})});function fn({text:e,streaming:n,host:t}){let r=n===!0,[o,i]=p(e);return g(()=>{if(o===e)return;if(!r){i(e);return}let s=requestAnimationFrame(()=>i(e));return()=>cancelAnimationFrame(s)},[o,r,e]),a(Z.Provider,{value:t,children:a(rn,{text:r?o:e,isStreaming:r})})}export{fn as CodexMarkdownRenderer};
@@ -1,3 +1,4 @@
1
+ import { type ReactNode } from "react";
1
2
  import "./navigation-rail.css";
2
3
  export interface NavigationRailAudio {
3
4
  installUnlock: () => () => void;
@@ -14,12 +15,19 @@ export interface ThreadUserMessageNavigationItem {
14
15
  response: string;
15
16
  inputTokens: number;
16
17
  outputTokens: number;
18
+ nativeTurnId?: string;
19
+ messageId?: string;
20
+ isLoaded?: boolean;
21
+ previewState?: "loading" | "loaded" | "unavailable";
17
22
  }
18
- export declare function ThreadUserMessageNavigationRail({ audio, beforeReveal, ensureItemMounted, items, scrollRoot, targetTopMarginPx }: {
23
+ export declare function ThreadUserMessageNavigationRail({ audio, beforeReveal, ensureItemMounted, items, onPreviewItem, renderPreview, onRevealError, scrollRoot, targetTopMarginPx }: {
19
24
  audio: NavigationRailAudio;
20
25
  beforeReveal: () => void;
21
- ensureItemMounted?: (item: ThreadUserMessageNavigationItem) => Promise<void>;
26
+ ensureItemMounted?: (item: ThreadUserMessageNavigationItem, isCurrent: () => boolean) => Promise<HTMLElement | null | void>;
22
27
  items: ThreadUserMessageNavigationItem[];
28
+ onPreviewItem?: (item: ThreadUserMessageNavigationItem) => Promise<void>;
29
+ renderPreview?: (item: ThreadUserMessageNavigationItem) => ReactNode;
30
+ onRevealError?: (error: unknown) => void;
23
31
  scrollRoot: HTMLElement | null;
24
32
  targetTopMarginPx?: number;
25
33
  }): import("react").JSX.Element | null;
@@ -1 +1 @@
1
- import{jsx as f,jsxs as re}from"react/jsx-runtime";import{useCallback as ie,useEffect as P,useMemo as B,useRef as g,useState as O}from"react";import{NavigationPreview as se}from"./navigation-preview.js";import"./navigation-rail.css";var ae=4,oe=10;function Z(T,h){if(T.size!==h.size)return!1;for(let u of T)if(!h.has(u))return!1;return!0}function ge({audio:T,beforeReveal:h,ensureItemMounted:u,items:i,scrollRoot:a,targetTopMarginPx:R=16}){let[_,ee]=O(()=>new Set(i.length===0?[]:[i[i.length-1].id])),[b,x]=O(null),[z,M]=O(null),[H,y]=O(!1),[E,te]=O(()=>new Set),{installUnlock:K,preload:L,playSequence:G}=T,V=g(null),v=g(null),N=g(!1),S=g(null),k=g(0),C=B(()=>i.map((e)=>e.id).join("\x00"),[i]),q=g(i);q.current=i;let D=g(E),F=g(_),J=g({itemIdsKey:C,scrollRoot:a}),W=J.current;if(W.itemIdsKey!==C||W.scrollRoot!==a)k.current+=1,J.current={itemIdsKey:C,scrollRoot:a};let m=B(()=>u===void 0?i.filter((e)=>E.has(e.id)):i,[u,i,E]),Y=B(()=>m.map((e)=>({inputTokens:e.inputTokens,outputTokens:e.outputTokens})),[m]);P(()=>K(),[K]),P(()=>()=>{k.current+=1},[]),P(()=>{x(null),y(!1),M(null),v.current=null,N.current=!1,S.current=null},[C,a]),P(()=>{L()},[L]),P(()=>{if(a===null)return;let e=new Set,t=new Map,o=new Set(q.current.map((r)=>r.id)),l=()=>{let r=new Set(t.values()),c=q.current.filter((d)=>r.has(d.id)).map((d)=>d.id),n=c.findIndex((d)=>e.has(d));if(n===-1)return;let I=n;for(let d=n+1;d<c.length;d++)if(e.has(c[d]))I=d;let j=new Set(c.slice(n,I+1));if(Z(F.current,j))return;F.current=j,ee(j)},w=new IntersectionObserver((r)=>{for(let c of r){let n=t.get(c.target);if(c.isIntersecting)e.add(n);else e.delete(n)}l()},{root:a,rootMargin:`-${R}px 0px 0px 0px`}),s=()=>{let r=new Set,c=new Set;for(let n of a.querySelectorAll("[data-content-search-unit-key]")){let I=n.dataset.contentSearchUnitKey;if(I===void 0||!o.has(I)||r.has(I))continue;if(r.add(I),c.add(n),t.has(n))continue;t.set(n,I),w.observe(n)}for(let n of t.keys()){if(c.has(n))continue;w.unobserve(n),e.delete(t.get(n)),t.delete(n)}if(Z(D.current,r))return;D.current=r,te(r)};s();let p=new MutationObserver(s);return p.observe(a,{childList:!0,subtree:!0}),()=>{p.disconnect(),w.disconnect()}},[C,a,R]);let Q=ie(async(e)=>{if(a===null)throw Error("Thread user-message navigation scroll root is missing");let t=k.current+1;if(k.current=t,h(),u!==void 0){await u(e);return}let o=a.querySelector(`[data-content-search-unit-key="${CSS.escape(e.id)}"]`);if(o===null)throw Error(`Thread user-message navigation target is missing: ${e.id}`);if(k.current!==t)return;o.scrollIntoView({behavior:"instant",block:"start"})},[h,u,a]);if(m.length<ae)return null;let A=V.current,ne=b===null||A===null||!A.contains(b.button)?0:ue(A,b.button),X=(e)=>{let t=e?.closest("[data-thread-user-message-navigation-item-id]"),o=V.current;if(t===void 0||t===null||!o.contains(t))return null;let l=t.dataset.threadUserMessageNavigationItemId,w=m.findIndex((s)=>s.id===l);return{button:t,item:m[w],index:w}},U=(e)=>{let t=v.current;if(t===null||t.pointerId!==e.pointerId)return;if(v.current=null,M(null),t.captureTarget.hasPointerCapture(e.pointerId))t.captureTarget.releasePointerCapture(e.pointerId)};return f("nav",{"aria-label":"User messages",className:"thread-user-message-navigation absolute start-4 top-1/2 z-20 -translate-y-1/2",children:f(se,{open:H,onOpenChange:y,side:"inline-end",sideOffset:0,align:"center",alignOffset:ne,trigger:f("div",{ref:V,"data-thread-user-message-navigation-rail-list":!0,"data-scrubbing":z===null?void 0:"",className:"thread-user-message-navigation-rail-list",onPointerEnter:()=>{S.current=null},onPointerDown:(e)=>{if(e.button!==0)return;let t=X(e.target instanceof Element?e.target:null);if(t===null)return;N.current=!1,v.current={pointerId:e.pointerId,itemId:t.item.id,itemIndex:t.index,captureTarget:t.button},t.button.setPointerCapture(e.pointerId),M(t.item.id),x(t),y(!0)},onPointerMove:(e)=>{let t=v.current;if(t===null){let p=X(e.target instanceof Element?e.target:null);if(p!==null){let r=S.current;if(r!==null&&r!==p.index)G(r,p.index,Y);S.current=p.index,x(p)}return}if(t.pointerId!==e.pointerId)return;let o=e.currentTarget.getBoundingClientRect(),l=Math.max(0,Math.min(m.length-1,Math.floor((e.clientY-o.top+e.currentTarget.scrollTop)/oe))),s={button:e.currentTarget.querySelectorAll("[data-thread-user-message-navigation-item-id]")[l],item:m[l],index:l};if(s.item.id===t.itemId)return;G(t.itemIndex,s.index,Y),S.current=s.index,v.current={...t,itemId:s.item.id,itemIndex:s.index},N.current=!0,M(s.item.id),x(s),Q(s.item)},onPointerUp:U,onPointerCancel:U,onLostPointerCapture:U,onPointerLeave:()=>{if(S.current=null,v.current===null&&!H)x(null)},children:f("div",{className:"flex flex-col",children:m.map((e,t)=>f("button",{type:"button","data-thread-user-message-navigation-item-id":e.id,"data-scrub-target":z===e.id?"":void 0,"aria-current":_.has(e.id)?"true":void 0,"aria-label":`Jump to user message ${t+1}`,className:"thread-user-message-navigation-row",onClick:(o)=>{if(N.current){N.current=!1;return}let l={button:o.currentTarget,item:e,index:t};x(l),y(!0),Q(e)},onFocus:(o)=>{x({button:o.currentTarget,item:e,index:t}),y(!0)},children:f("span",{className:"flex h-0.5 w-[30px] items-center",children:f("span",{className:"thread-user-message-navigation-marker"})})},e.id))})}),children:b!==null&&re("div",{className:"bg-popover/95 text-popover-foreground ring-border w-80 max-w-[calc(100vw-1rem)] overflow-hidden rounded-xl p-2 text-sm leading-5 shadow-xl ring-[0.5px] backdrop-blur-sm",children:[f("div",{className:"min-w-0 truncate font-medium",children:b.item.label}),b.item.response.length>0&&f("div",{className:"text-muted-foreground mt-1 line-clamp-3",children:b.item.response})]})})})}function ue(T,h){let u=T.getBoundingClientRect(),i=h.getBoundingClientRect();return i.top+i.height/2-(u.top+u.height/2)}export{ge as ThreadUserMessageNavigationRail};
1
+ import{jsx as v,Fragment as ve,jsxs as we}from"react/jsx-runtime";import{useCallback as ye,useEffect as q,useLayoutEffect as Se,useMemo as X,useRef as b,useState as M}from"react";import{NavigationPreview as Te}from"./navigation-preview.js";import"./navigation-rail.css";var ke=4,fe=10;function Ce(x,w){let h=new Map(w.flatMap((f)=>f.itemIds.map((S)=>[S,f.key]))),d=Array(x.length),P;for(let f=x.length-1;f>=0;f--)P=h.get(x[f])??P,d[f]=P;let j=Math.max(-1,...w.map((f)=>f.key))+1,E=new Set,n=[];for(let[f,S]of x.entries()){let T=h.get(S),g=n.at(-1);if(!g||T!==void 0&&T!==g.key||T===void 0&&g.itemIds.length>=64&&d[f]!==g.key){let y=T!==void 0&&!E.has(T)?T:j++;g={key:y,startIndex:f,itemIds:[]},n.push(g),E.add(y)}g.itemIds.push(S)}return n}function ge(x,w){if(x.size!==w.size)return!1;for(let h of x)if(!w.has(h))return!1;return!0}function Ee({audio:x,beforeReveal:w,ensureItemMounted:h,items:d,onPreviewItem:P,renderPreview:j,onRevealError:E,scrollRoot:n,targetTopMarginPx:f=16}){let[S,T]=M(()=>new Set(d.length===0?[]:[d[d.length-1].id])),[g,y]=M(null),[F,K]=M(null),[Z,A]=M(!1),[W,me]=M(()=>new Set),[pe,he]=M(!0),[Ie,G]=M(null),{installUnlock:ee,preload:te,playSequence:ne}=x,L=b(null),k=b(null),H=b(!1),B=b(null),O=b(0),C=b(null),U=b(new Set),_=X(()=>d.map((e)=>e.id).join("\x00"),[d]),D=b(d);D.current=d;let re=b(W),se=b(S),ie=b({itemIdsKey:_,scrollRoot:n});if(ie.current.scrollRoot!==n)O.current+=1,ie.current={itemIdsKey:_,scrollRoot:n};let m=X(()=>h===void 0?d.filter((e)=>W.has(e.id)):d,[h,d,W]),ae=X(()=>m.map((e)=>({inputTokens:e.inputTokens,outputTokens:e.outputTokens})),[m]),z=b({ids:"",groups:[]}),oe=m.map((e)=>e.id).join("\x00");if(z.current.ids!==oe)z.current={ids:oe,groups:Ce(m.map((e)=>e.id),z.current.groups)};q(()=>ee(),[ee]),q(()=>()=>{if(O.current+=1,C.current!==null)clearTimeout(C.current)},[]),q(()=>{y(null),A(!1),K(null),k.current=null,H.current=!1,B.current=null,G(null),U.current.clear()},[n]),q(()=>{te()},[te]),q(()=>{if(n===null)return;let e=new Set,t=new Map,r=new Set(D.current.map((o)=>o.id)),s=()=>{let o=new Set(t.values()),l=D.current.filter((p)=>o.has(p.id)).map((p)=>p.id),u=l.findIndex((p)=>e.has(p));if(u===-1)return;let I=u;for(let p=u+1;p<l.length;p++)if(e.has(l[p]))I=p;let N=new Set(l.slice(u,I+1));if(ge(se.current,N))return;se.current=N,T(N)},i=new IntersectionObserver((o)=>{for(let l of o){let u=t.get(l.target);if(l.isIntersecting)e.add(u);else e.delete(u)}s()},{root:n,rootMargin:`-${f}px 0px 0px 0px`}),a=()=>{let o=new Set,l=new Set;for(let u of n.querySelectorAll("[data-content-search-unit-key]")){let I=u.dataset.contentSearchUnitKey;if(I===void 0||!r.has(I)||o.has(I))continue;o.add(I);let N=u.closest("[data-turn-key]"),p=N===null||l.has(N)?u:N;if(l.add(p),t.has(p))continue;t.set(p,I),i.observe(p)}for(let u of t.keys()){if(l.has(u))continue;i.unobserve(u),e.delete(t.get(u)),t.delete(u)}if(s(),ge(re.current,o))return;re.current=o,me(o)};a();let c=new MutationObserver((o)=>{if(o.some((u)=>[...u.addedNodes,...u.removedNodes].some((I)=>I instanceof Element&&(I.matches("[data-turn-key], [data-content-search-unit-key]")||I.querySelector("[data-turn-key], [data-content-search-unit-key]")!==null))))a()});return c.observe(n,{childList:!0,subtree:!0}),()=>{c.disconnect(),i.disconnect()}},[_,n,f]);let J=m.find((e)=>S.has(e.id))?.id??m.at(-1)?.id;Se(()=>{let e=L.current;if(e===null||k.current!==null||J===void 0)return;let t=e.querySelector(`[data-thread-user-message-navigation-item-id="${CSS.escape(J)}"]`);if(t===null)return;let r=e.getBoundingClientRect(),s=t.getBoundingClientRect();if(s.top<r.top)e.scrollTop+=s.top-r.top;else if(s.bottom>r.bottom)e.scrollTop+=s.bottom-r.bottom+1},[J,_]),q(()=>{let e=n?.querySelector("[data-thread-user-message-navigation-content]");if(!n||!e)return;let t=()=>{let s=n.getBoundingClientRect(),i=e.getBoundingClientRect();if(s.width===0||i.width===0)return;let a=n.offsetWidth>0?s.width/n.offsetWidth:1;he((i.left-s.left)/a>=48)},r=new ResizeObserver(t);return r.observe(n),r.observe(e),t(),()=>r.disconnect()},[n]);let be=ye(async(e,t="smooth")=>{if(n===null)throw Error("Thread user-message navigation scroll root is missing");let r=O.current+1;O.current=r,w();let s=()=>n.querySelector(`[data-content-search-unit-key="${CSS.escape(e.id)}"]`),i=s(),a=i!==null&&n.clientHeight>0&&i.closest("[data-turn-key]")!==null&&Math.abs(i.getBoundingClientRect().top-n.getBoundingClientRect().top)>n.clientHeight*2;if((i===null||a)&&h!==void 0){if(t==="instant"&&e.isLoaded===!1)return;i=await h(e,()=>O.current===r)??s(),t="instant"}if(O.current!==r)return;if(i===null)return;let c=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches===!0;i.scrollIntoView({behavior:c?"instant":t,block:"start"}),i.querySelector("[data-user-message-bubble], [data-composer-attachment-pill]")?.animate?.([{backgroundColor:"color-mix(in srgb, var(--foreground) 14%, transparent)"},{backgroundColor:"color-mix(in srgb, var(--foreground) 14%, transparent)",offset:0.35},{backgroundColor:"transparent"}],{duration:c?0:1000,easing:"cubic-bezier(0.23, 1, 0.32, 1)"})},[w,h,n]);if(m.length<ke||!pe)return null;let Y=()=>{if(C.current!==null)clearTimeout(C.current);C.current=null},ue=(e,t=!1)=>{if(Y(),P===void 0||e.isLoaded!==!1||U.current.has(e.turnKey))return;let r=()=>{C.current=null,U.current.add(e.turnKey),P(e).catch(()=>U.current.delete(e.turnKey))};if(t)r();else C.current=setTimeout(r,150)},V=g===null?null:m.find((e)=>e.id===g.item.id)??m.find((e)=>e.nativeTurnId!==void 0&&e.nativeTurnId===g.item.nativeTurnId)??g.item,ce=(e,t="smooth")=>{be(e,t).catch((r)=>{if(E)E(r);else throw r})},de=m.findIndex((e)=>e.id===(F??Ie)),Q=L.current,xe=g===null||Q===null||!Q.contains(g.button)?0:Ne(Q,g.button),le=(e)=>{let t=e?.closest("[data-thread-user-message-navigation-item-id]"),r=L.current;if(t===void 0||t===null||!r.contains(t))return null;let s=t.dataset.threadUserMessageNavigationItemId,i=m.findIndex((a)=>a.id===s);return{button:t,item:m[i],index:i}},R=(e)=>{let t=k.current;if(t===null||t.pointerId!==e.pointerId)return;if(k.current=null,K(null),t.captureTarget.hasPointerCapture(e.pointerId))t.captureTarget.releasePointerCapture(e.pointerId)};return v("nav",{"aria-label":"User messages",className:"thread-user-message-navigation absolute start-4 top-1/2 z-20 -translate-y-1/2",children:v(Te,{open:Z,onOpenChange:A,side:"inline-end",sideOffset:0,align:"center",alignOffset:xe,trigger:v("div",{ref:L,"data-thread-user-message-navigation-rail-list":!0,"data-scrubbing":F===null?void 0:"",className:"thread-user-message-navigation-rail-list",onPointerEnter:()=>{B.current=null},onPointerDown:(e)=>{if(e.button!==0)return;Y();let t=le(e.target instanceof Element?e.target:null);if(t===null)return;H.current=!1,k.current={pointerId:e.pointerId,itemId:t.item.id,itemIndex:t.index,captureTarget:t.button},t.button.setPointerCapture(e.pointerId),K(t.item.id),y(t),A(!0)},onPointerMove:(e)=>{let t=k.current;if(t===null){let c=le(e.target instanceof Element?e.target:null);if(c!==null){G(c.item.id);let o=B.current;if(o!==null&&o!==c.index)ne(o,c.index,ae);B.current=c.index,y((l)=>l?.item.id===c.item.id?l:c),ue(c.item)}return}if(t.pointerId!==e.pointerId)return;if((e.buttons&1)===0){R(e);return}let r=e.currentTarget.getBoundingClientRect(),s=Math.max(0,Math.min(m.length-1,Math.floor((e.clientY-r.top+e.currentTarget.scrollTop)/fe))),a={button:e.currentTarget.querySelectorAll("[data-thread-user-message-navigation-item-id]")[s],item:m[s],index:s};if(a.item.id===t.itemId)return;ne(t.itemIndex,a.index,ae),B.current=a.index,k.current={...t,itemId:a.item.id,itemIndex:a.index},H.current=!0,K(a.item.id),y(a),ce(a.item,"instant")},onPointerUp:R,onPointerCancel:R,onLostPointerCapture:R,onPointerLeave:()=>{if(Y(),G(null),B.current=null,k.current===null&&!Z)y(null)},children:v("div",{className:"flex flex-col",children:z.current.groups.map((e)=>v("div",{className:"flex w-9 shrink-0 flex-col [content-visibility:auto]",style:{height:e.itemIds.length*fe},children:m.slice(e.startIndex,e.startIndex+e.itemIds.length).map((t,r)=>{let s=e.startIndex+r,i=Math.abs(s-de),a=de<0||i>3?void 0:[1,0.7,0.4,0.2][i];return v("button",{type:"button","data-thread-user-message-navigation-item-id":t.id,"data-scrub-target":F===t.id?"":void 0,"aria-current":S.has(t.id)?"true":void 0,"aria-label":`Jump to user message ${s+1}`,className:"thread-user-message-navigation-row",onClick:(c)=>{if(H.current){H.current=!1;return}let o={button:c.currentTarget,item:t,index:s};y(o),A(!0),ce(t)},onFocus:(c)=>{ue(t,!0),y({button:c.currentTarget,item:t,index:s}),A(!0)},children:v("span",{className:"flex h-0.5 w-[30px] items-center",children:v("span",{className:"thread-user-message-navigation-marker",style:a===void 0?void 0:{"--marker-progress":a}})})},t.id)})},e.key))})}),children:V!==null&&v("div",{className:"bg-popover/95 text-popover-foreground ring-border w-80 max-w-[calc(100vw-1rem)] overflow-hidden rounded-xl p-2 text-sm leading-5 shadow-xl ring-[0.5px] backdrop-blur-sm",children:j?j(V):we(ve,{children:[v("div",{className:"min-w-0 truncate font-medium",children:V.label}),V.response.length>0&&v("div",{className:"text-muted-foreground mt-1 line-clamp-3",children:V.response})]})})})})}function Ne(x,w){let h=x.getBoundingClientRect(),d=w.getBoundingClientRect();return d.top+d.height/2-(h.top+h.height/2)}export{Ee as ThreadUserMessageNavigationRail};
@@ -1081,6 +1081,38 @@
1081
1081
  max-width: 77%;
1082
1082
  }
1083
1083
 
1084
+ .codex-turn-loading {
1085
+ position: absolute;
1086
+ inset: 0;
1087
+ pointer-events: none;
1088
+ }
1089
+
1090
+ .codex-turn-loading-lines {
1091
+ position: sticky;
1092
+ top: 0;
1093
+ display: flex;
1094
+ flex-direction: column;
1095
+ gap: 12px;
1096
+ padding-block: 32px;
1097
+ }
1098
+
1099
+ .codex-turn-loading-lines span {
1100
+ width: 80%;
1101
+ height: 12px;
1102
+ border-radius: 4px;
1103
+ background: var(--codex-bg-tertiary);
1104
+ }
1105
+
1106
+ .codex-turn-loading-lines span:first-child {
1107
+ width: 33%;
1108
+ height: 20px;
1109
+ margin-inline-start: auto;
1110
+ }
1111
+
1112
+ .codex-turn-loading-lines span:last-child {
1113
+ width: 60%;
1114
+ }
1115
+
1084
1116
  .codex-user-mentions,
1085
1117
  .codex-user-images {
1086
1118
  display: flex;